0

I am currently trying to write a DLL for use in another program. In this DLL I am using condition variables which are in boost::thread which requires boost::system. I want to link the boost libraries statically so that my program only needs my dll and nothing from boost.

I am able to link the thread library statically so that I don't need to give my program the boost thread dll. But, I can't get static linking to work with boost::system. So far, it will only work if I link it dynamically. Statically, I get the following compilation error when compiling my program

E:\boost\boost_1_53_0\boost\system\error_code.hpp|214|undefined reference to `boost::system::generic_category()'|

Here's my console output when builiding the dll

-------------- Build: Debug in myProgram_DLL ---------------

mingw32-g++.exe  -Wall -g -DBUILD_DLL -DBOOST_THREAD_USE_LIB -DBOOST_SYSTEM_NO_DEPRECATED    -I"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\include" -IE:\boost\boost_1_53_0  -c "Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\src\MyProgramMessage.cpp" -o obj\Debug\src\MyProgramMessage.o
mingw32-g++.exe  -Wall -g -DBUILD_DLL -DBOOST_THREAD_USE_LIB -DBOOST_SYSTEM_NO_DEPRECATED    -I"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\include" -IE:\boost\boost_1_53_0  -c "Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\src\MessageQueue.cpp" -o obj\Debug\src\MessageQueue.o
mingw32-g++.exe  -Wall -g -DBUILD_DLL -DBOOST_THREAD_USE_LIB -DBOOST_SYSTEM_NO_DEPRECATED    -I"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\include" -IE:\boost\boost_1_53_0  -c "Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -shared -Wl,--output-def=bin\Debug\libmyProgram_DLL.dll.def -Wl,--out-implib=bin\Debug\libmyProgram_DLL.dll.a -Wl,--dll -LE:\boost\boost_1_53_0\bin.v2\libs\thread\build\gcc-mingw-4.4.1\debug\link-static\runtime-link-static\threading-multi -LE:\boost\boost_1_53_0\bin.v2\libs\system\build\gcc-mingw-4.4.1\debug\link-static\runtime-link-static\threading-multi  obj\Debug\src\MyProgramMessage.o obj\Debug\src\MessageQueue.o obj\Debug\main.o   -o bin\Debug\myProgram_DLL.dll  -luser32 -lboost_thread-mgw44-mt-sd-1_53 -lboost_system-mgw44-mt-sd-1_53 
Creating library file: bin\Debug\libmyProgram_DLL.dll.a
Output size is 2.10 MB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings

Here's my console output when builiding the test program

-------------- Build: Debug in myProgram_DLL_Test ---------------

mingw32-g++.exe -Wall  -g    -I"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL" -IE:\boost\boost_1_53_0 -IE:\boost\boost_1_53_0\bin.v2\libs -I"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\src" -I"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\include"  -c "Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL_Test\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -LE:\boost\boost_1_53_0 -L"Z:\Eigene Dateien Server\Andre\myProgram\myProgram_DLL\bin\Debug"  -o bin\Debug\myProgram_DLL_Test.exe obj\Debug\main.o    -lmyProgram_DLL 
obj\Debug\main.o: In function `_static_initialization_and_destruction_0':
E:/boost/boost_1_53_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
E:/boost/boost_1_53_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
E:/boost/boost_1_53_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
3 errors, 0 warnings

If I link the following file to my test program , it will compile

E:\boost\boost_1_53_0\bin.v2\libs\system\build\gcc-mingw-4.4.1\debug\link-static\runtime-link-static\threading-multi\libboost_system-mgw44-mt-sd-1_53

I have found lots of threads to do with my error but only those that involve linking boost::system to the project. I want to avoid this and only link boost::system to my DLL

How can I link everything correctly so that I don't need to link boost system to my test program, only to my DLL?? I am using code blocks, boost 1.53 and MinGW 4.4.1

Thanks in advance

Andre
  • 115
  • 1
  • 7

1 Answers1

0

Ok,

I've solved my problem. It was to do with the way I was including headers. I had my class header files defined in my dll header file so, when I included the dll header file in my exe project, it wanted me to link some boost libraries etc that are used n the classes.

By moving the includes to my dll main.cpp, the problem was fixed. I now only need to link myDLL to my exe project

For example, I had the includes like this:

myDLL.h

#include "myClass1.h"
#include "myClass2.h"

main.cpp // of my exe project

#include "myDLL.h"

I now have it like this:

main.cpp // of my dll project

#include "myDLL.h"
#include "myClass1.h"
#include "myClass2.h"

main.cpp // of my exe project

#include "myDLL.h"
Andre
  • 115
  • 1
  • 7