Author Topic: Linking static libraries into a DLL  (Read 13551 times)

wildcards

  • Guest
Linking static libraries into a DLL
« on: August 10, 2007, 09:58:19 am »
Hello all

I come in an issue wile linking several static libraries into a DLL.

In my workspace, I have the following 4 projects :
- 2 projects for creating 2 static libraries
- 1 project for creating the DLL, which is only composed by the 2 static libraries
- 1 Project for executable linked against the DLL

The idea is to separately compile statics libraries, and then link them all into a single DLL.

The library compiles fines, the executable compiles fine too, but when it comes to link executable, the symbols are not found, while they are in static libraries.

As usual for libraries, it have tryed __declspec( dllexport ) and __declspec( dllimport ) but that change nothing.
In linker settings, I usually add -Wl,--disable-auto-import and --export-all-symbols, but with or without them changes nothing.

As a test, it works fine to compile the 2 statics libraries as DLL, and then to link executable against the 2 of them.
I'm using a recent nightly build of CB, and compiles using GCC. I'm testing on Windows, but I would like to make all this project works also on Linux.

First, do you know if this is possible ?
I often work with statics lib or DLLs, but I never tryed in this way ....
Then, what can I do ?

I have Googled for this without any success  :?

Thanks for your help

Fabien
« Last Edit: August 10, 2007, 10:06:09 am by wildcards »

wxLearner

  • Guest
Re: Linking static libraries into a DLL
« Reply #1 on: August 10, 2007, 10:23:36 am »
Hello,
try the linker option
Code
--whole-archive
Look here for more command line options.

wildcards

  • Guest
Re: Linking static libraries into a DLL
« Reply #2 on: August 10, 2007, 11:22:54 am »
Thanks a lot, that solve my problem !  :D

For those who comes on that issue, here is how to do:

1. create static lib projects, create a DLL project, and an executable project
2. in the DLL project, go in "Build Options" -> "Linker settings"
--> do NOT add in "Link Libraries" your statics libraries (those you want to include in the DLL)
--> in "Other Link options", add:
Code
-Wl,--whole-archive
../bin/libproj1.a
../bin/libproj2.a
-Wl,--no-whole-archive

The libraries between "-Wl,--whole-archive" and "-Wl,--no-whole-archive" are included in the DLL.
For searching these libraries, the linker do not seem to search in the paths used to include libraries with "-lmylib". But OK, that works  :D

Fabien