Use gcc option fpic for shared objects
Then we build the same code on Windows with MinGW. At first by directly linking the dynamic link library. To make the build process more convenient and more flexible, we use CMake at this point. Last but not least, a few words about the interoperability of libraries created with different compilers ABI compatibility follow.
The final version of the minimalistic portable code demo, that is gradually developed in this post, is available on github. The header of our shared library is shared. Our application is implemented in main. The command above compiles shared. The compiler output -o is written to libshared. The option -g tells nm that we are just interested in external symbols. Fine, our library exports the symbols f and X:: We can do this with the command ldd:.
To solve this problem, we must somehow specify where the library can be found. You can take the source code from above without any changes and build it very similar like on Linux:. The above lines produce shared.
But this is not the common way to work with shared libraries on windows because just a few compilers support this - the Microsoft Visual Studio Compiler is not among them. Join Stack Overflow to learn, share knowledge, and build your career.
I know the ' -fPIC ' option has something to do with resolving addresses and independence between individual modules, but I'm not sure what it really means. If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table.
Email Sign Up or sign in with Google. What does -fPIC mean when building a shared library? FXQuantTrader 5, 2 20 There is a difference between fpic and fPIC. They both do the same thing but fpic uses a shorter relative offset where available. Thus compiling with fpic can potentially produce smaller files. Unfortunately it does not always work as expected so use fPIC.