What's the proper way to link against an executable on Windows?

后端 未结 2 526
你的背包
你的背包 2021-01-21 12:10

I need to use some symbols from the main executable in a plugin.

Linking against the executable causes the following linker errors:

i686-w64-mingw32-g++          


        
2条回答
  •  遇见更好的自我
    2021-01-21 12:19

    Like Keith Marshall stated in the comments, -Wl,--out-implib indeed works in combination with either:

    • -Wl,--export-all-symbols

    • by declaring symbols with __declspec(dllexport)

    • or by providing a .def file

    I went with the third option and wrote a bash script to generate a def file / version scripts on-the-fly to avoid exporting a lot of unneeded symbols.

    The script can be found here.

    Use it like:

    export SYMBOLS_TO_EXPORT="*tools* *network* _Z8compressPvRjPKvjib ..." # use mangled names and skip leading underscores on i686
    export HOSTPREFIX=i686-w64-mingw32 # unneeded on Windows
    i686-w64-mingw32-g++ $(OBJS) `./gen_export_file $(OBJS)` -Wl,--out-implib=foo.exe.a -o foo.exe
    

提交回复
热议问题