[C++] only extern declaration for imported functions?

Started by
2 comments, last by cpp forever 17 years, 6 months ago
I'm building a program, which uses some import library. I have successfully created .a import library (Dev-C++, GCC, Win32) using dlltool, but can't link correctly with my program. I have found that include files (can't change them) for that library has functions in style of:

extern int
proto_register_protocol(const char *name, const char *short_name, const char *filter_name);

So there is no __declspec(import) (or else) declared. When I change 'extern' to 'extern "C" __declspec(import)' my program links ok. But I don't want to change headers. How can I force linker to find 'proto_register_protocol' in import libraries and not showing me 'undefined reference to'?
ai-blog.org: AI is discussed here.
Advertisement
OK, the "extern "C" __declspec(import)" is doing two things. Firstly, the extern "C" is telling the compiler to use C-style function name decoration for this function as opposed to C++ style. The second bit, the "__declspec(import)" is telling the compiler/linker that the function is in a DLL that is to be found at run time. Your program may compile/link but I don't think it will run. To resolve this, you must add the library name to the list of inputs to the linker command line - how you do this is dependent on the environment you're using. I've not used Dev-C++ so you'll need to find out from somewhere else.

Skizz
I have said that I have add it.
-lethereal


When not adding library and using 'extern "C" __declspec(import)' instead of 'extern' I get [Linker error] undefined reference to `_imp__proto_register_protocol' .
ai-blog.org: AI is discussed here.
solved this issue putting includes into 'extern "C"'.
ai-blog.org: AI is discussed here.

This topic is closed to new replies.

Advertisement