Jump to content
  • Advertisement
Sign in to follow this  
cpp forever

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

This topic is 4292 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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'?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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' .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!