Linking C libraries to C++?
-
Pre-compiled a C library using msvc 6, blah.lib In a new C++ project, include header and library location in Tools->Options->Directories, included header in the C++ file and include library in the Settings->Link tab I get a linker error stating: main.obj : error LNK2001: unresolved external symbol "int __cdecl hInitialise(int,struct HWND__ *,struct HDC__ *,unsigned int)" (?hInitialise@@YAHHPAUHWND__@@PAUHDC__@@I@Z) I was not able to recompile the library into C++, cause of header problems....
-
Pre-compiled a C library using msvc 6, blah.lib In a new C++ project, include header and library location in Tools->Options->Directories, included header in the C++ file and include library in the Settings->Link tab I get a linker error stating: main.obj : error LNK2001: unresolved external symbol "int __cdecl hInitialise(int,struct HWND__ *,struct HDC__ *,unsigned int)" (?hInitialise@@YAHHPAUHWND__@@PAUHDC__@@I@Z) I was not able to recompile the library into C++, cause of header problems....
This smells like a name mangling issue. Try to wrap the header file that contains your function declarations with
extern "C"
{
...
... all of your functions
...
}and then rebuild your library and then rebuild your app. Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
-
This smells like a name mangling issue. Try to wrap the header file that contains your function declarations with
extern "C"
{
...
... all of your functions
...
}and then rebuild your library and then rebuild your app. Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden] Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
Thanks for the suggestion Chris, it didn't work. The cpp files generated a host of other errors. I googled extern "C" to see how else I could use it. I tried putting the function declaration at the top of my file and used: extern "C" int hInitialise(int count, HWND window, HDC screen, unsigned int flags); Got a compile error: main.cpp(13) : error C2732: linkage specification contradicts earlier specification for 'hInitialise' But I copied it straight from the header....:confused:
-
Thanks for the suggestion Chris, it didn't work. The cpp files generated a host of other errors. I googled extern "C" to see how else I could use it. I tried putting the function declaration at the top of my file and used: extern "C" int hInitialise(int count, HWND window, HDC screen, unsigned int flags); Got a compile error: main.cpp(13) : error C2732: linkage specification contradicts earlier specification for 'hInitialise' But I copied it straight from the header....:confused:
You don't have to copy anything. In your C++ code do this:
extern "C"
{
#include "your_c_header.h"
}--Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ | You Are Dumb Magnae clunes mihi placent, nec possum de hac re mentiri.