1

I'm working on a cross-platform c++/qt project with a plugin system, we are using so files on linux and dll on windows. We are using gcc on Linux and Visual Studio 2010 on Windows through cmake. The problem is our plugins sometimes need to call a function from the application source code, which is working fine on Linux with gcc by just including the header files. But on Visual Studio, we got unresolved external symbol errors.

Is it because so and dll files works differently?

thank you.

Jkmn
  • 571
  • 5
  • 11

1 Answers1

2

The default behaviour for exporting symbols from dlls on Windows is exactly opposite: by default, symbols are invisible, you need to export them explicitly. With VC++ this is done by __declspec(dllexport) declarators.

EDIT (Information added): You are entering a region of non-standardized, system specific behaviour... There are much more problems associated with writing cross-platform "pluggable" component systems in C++ than you might be expecting. On Windows there are so called import libraries, which define all symbols exported from a dll. You have to link against these libraries in order to resolve these symbols. This is called implicit linking. You can also link explicitly which means loading dll and its exported symbols at run-time. However all these are just technical details compared to so called binary compatibility issues, which will almost certainly kill you, if not considered during the design of your component system.

I am wondering about one thing: You said you're using Qt. Qt application framework has got it's own cross platform conventions and rules for writing and building pluggable components. Why don't you stick with these...?

Paul Michalik
  • 4,331
  • 16
  • 18
  • Yeah but that's not enough It seems I have to link the *.lib from the main executable. – Jkmn Sep 22 '12 at 17:35
  • Thank you for going further. So if I want my dll to compile I need to link the import library built from my main application? that's what is bothering me. – Jkmn Sep 23 '12 at 13:10
  • Well that's one possibility, the so called "implicit linking". There are other ways to accomplish this, but this is the most straightforward one... – Paul Michalik Sep 24 '12 at 14:44
  • There is no reason to link .lib. Consider I have a 3rd party library, which supplies me only .h and .dll.... – Robin Hsu Mar 26 '18 at 09:23
  • In this case you can't use implicit linking. You must load the dll at run time and extract the symbols manually. This is only feasible for C API functions and the header file is there merely for documentation purposes. – Paul Michalik Mar 27 '18 at 16:11