5

I'm currently trying to compile a dynamically linked library (for a plugin system) using Windows and MinGW.

I compile each objects using this command line :

mingw-g++ -fPIC test.cpp

And the library using this line:

mingw-g++ -rdynamic -shared -Wl,-soname,test.so.1 -o test.so test.o

It doesn't work at all (using GCC with Linux, a similar line works though) : fPIC and rdynamic are ignored for some reason. And while trying to make the library, it fails because the compiler try to link it with objects that are supposed to be resolved as I dynamically link it with the main binary.

So how do you compile this using MinGW?

Thanks :) !

1 Answer 1

9

-fPIC and -rdynamic are ignored because they are unused for Windows.

Also, .so is not the correct output extension for libraries on Windows.

To make a shared library for/on windows with GCC:

mingw-g++ -c file.cpp -o file.o
mingw-g++ -shared -Wl,--out-implib,libfile.a -o file.dll file.o 

No more, no less.

And, documentation is always lovely to have: http://www.mingw.org/wiki/sampleDLL

Sign up to request clarification or add additional context in comments.

2 Comments

So basically when a compiler flag is set and the conpiler does not know about it, it is ignored ? I thought that the compiler should throw an error or at least a warning
@Bionix depends on the option and on the compiler. Sometimes it leads to less headaches when ignoring such an option, such as in this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.