Trying to get a C function built with MSVC

Started by Bryan Montgomeryabout 16 years ago3 messagesgeneral
Jump to latest
#1Bryan Montgomery
monty@english.net

Hello,
I have a very simple function that I've created. I can compile it in linux
without any problems. However, I've tried creating a dll for windows and am
not having much luck.

I first tried MSVC 2008 but after seeing some comments have tried compiling
it in MSVC 2005 as well.

In both I get several errors, whether I compile the code as c++ and use an
extern C block, or compile the code as C.

I've tried creating new projects from both ides for dlls, as well as trying
to create a project from an external source file.

I'm using postgres version 8.3.5. I'm also including the port\win32_msvc
directory as well as the port\win32 include directory.

I was wondering if someone has a packaged 'solution' (makefile /def /.sln
whatever :) that they can post / send? At this point I'm stumped with just
trying to build a basic dll with the postgres headers.

The errors below are the ones that I'm struggling with now.

Thanks - Bryan.

warning C4005: '_WIN32_WINNT' : macro redefinition c:\program
files\postgresql\include\server\pg_config_os.h 7
error C2894: templates cannot be declared to have 'C' linkage c:\program
files\microsoft visual studio 8\vc\platformsdk\include\wspiapi.h 44
error C2894: templates cannot be declared to have 'C' linkage c:\program
files\microsoft visual studio 8\vc\platformsdk\include\wspiapi.h 44
error C2466: cannot allocate an array of constant size 0 c:\program
files\microsoft visual studio 8\vc\include\sys\utime.inl 44

#2Magnus Hagander
magnus@hagander.net
In reply to: Bryan Montgomery (#1)
Re: Trying to get a C function built with MSVC

2010/2/23 Bryan Montgomery <monty@english.net>:

Hello,
I have a very simple function that I've created. I can compile it in linux without any problems. However, I've tried creating a dll for windows and am not having much luck.

I first tried MSVC 2008 but after seeing some comments have tried compiling it in MSVC 2005 as well.

With 8.4 and earlier, only MSVC2005 is supported. If you're trying on
9.0, MSVC 2008 should be fine.

In both I get several errors, whether I compile the code as c++ and use an extern C block, or compile the code as C.

They definitely should be C. I wouldn't recommend C++ with extern defines.

I've tried creating new projects from both ides for dlls, as well as trying to create a project from an external source file.

I'm using postgres version 8.3.5. I'm also including the port\win32_msvc directory as well as the port\win32 include directory.

I was wondering if someone has a packaged 'solution' (makefile /def /.sln whatever :) that they can post / send? At this point I'm stumped with just trying to build a basic dll with the postgres headers.

I don't know of a packaged one, but your best bet is probably to
download the source and run the "mkvcbuild" script on it. Then look at
one of the projects generated for a contrib project - they are the
most likely to be close to what you want.

warning C4005: '_WIN32_WINNT' : macro redefinition    c:\program files\postgresql\include\server\pg_config_os.h    7

Are you defining _WIN32_WINNT yourself somewhere? Or including
something else before the postgres headers that define it?

error C2894: templates cannot be declared to have 'C' linkage    c:\program files\microsoft visual studio 8\vc\platformsdk\include\wspiapi.h    44
error C2894: templates cannot be declared to have 'C' linkage    c:\program files\microsoft visual studio 8\vc\platformsdk\include\wspiapi.h    44
error C2466: cannot allocate an array of constant size 0    c:\program files\microsoft visual studio 8\vc\include\sys\utime.inl    44

These are all coming out of your SDK files. Can you build your
projects if you *don't* include the postgres headers at all? Perhaps
you are stuck with one of those platform sdk mismatches we've seen now
and then?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

#3Bryan Montgomery
monty@english.net
In reply to: Magnus Hagander (#2)
Re: Trying to get a C function built with MSVC

Thanks for the suggestion. I wasn't able to get the whole pg to compile -
but I was able to take one of the contrib packages and use that as a
template for my needs.

Bryan.

On Wed, Feb 24, 2010 at 2:00 AM, Magnus Hagander <magnus@hagander.net>wrote:

Show quoted text

2010/2/23 Bryan Montgomery <monty@english.net>:

Hello,
I have a very simple function that I've created. I can compile it in

linux without any problems. However, I've tried creating a dll for windows
and am not having much luck.

I first tried MSVC 2008 but after seeing some comments have tried

compiling it in MSVC 2005 as well.

With 8.4 and earlier, only MSVC2005 is supported. If you're trying on
9.0, MSVC 2008 should be fine.

In both I get several errors, whether I compile the code as c++ and use

an extern C block, or compile the code as C.

They definitely should be C. I wouldn't recommend C++ with extern defines.

I've tried creating new projects from both ides for dlls, as well as

trying to create a project from an external source file.

I'm using postgres version 8.3.5. I'm also including the port\win32_msvc

directory as well as the port\win32 include directory.

I was wondering if someone has a packaged 'solution' (makefile /def /.sln

whatever :) that they can post / send? At this point I'm stumped with just
trying to build a basic dll with the postgres headers.

I don't know of a packaged one, but your best bet is probably to
download the source and run the "mkvcbuild" script on it. Then look at
one of the projects generated for a contrib project - they are the
most likely to be close to what you want.

warning C4005: '_WIN32_WINNT' : macro redefinition c:\program

files\postgresql\include\server\pg_config_os.h 7

Are you defining _WIN32_WINNT yourself somewhere? Or including
something else before the postgres headers that define it?

error C2894: templates cannot be declared to have 'C' linkage

c:\program files\microsoft visual studio
8\vc\platformsdk\include\wspiapi.h 44

error C2894: templates cannot be declared to have 'C' linkage

c:\program files\microsoft visual studio
8\vc\platformsdk\include\wspiapi.h 44

error C2466: cannot allocate an array of constant size 0 c:\program

files\microsoft visual studio 8\vc\include\sys\utime.inl 44

These are all coming out of your SDK files. Can you build your
projects if you *don't* include the postgres headers at all? Perhaps
you are stuck with one of those platform sdk mismatches we've seen now
and then?

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/