#include boost without using libs linux
The problem: At the moment im compiling on Ubuntu but my server is running Fedora/Redhat. Ubunutu uses boost 1.42 and linux latest at this very moment is 1.41. So what i decided was to download the boost lib and put it in the folder of my workspace Here is the directory structure
/workspace /myprogram /src /main.cpp /Debug /main /boost_1_42_0 /downloaded from boost.com
#include "../../boost_1_42_0/boost/regex.hpp"
Is this even posible or am i barking up the wrong tree. I have tried to compile it but it failed (ofcourse) with 13 errors If i missed some information please ask for it, il try providing it Make File (My Program is called vlogd)
################################################################################ # Automatically-generated file. Do not edit! ################################################################################ -include ../makefile.init RM := rm -rf # All of the sources participating in the build are defined here -include sources.mk -include subdir.mk -include src/subdir.mk -include src/class/vException/subdir.mk -include src/class/mysqlcppapi/subdir.mk -include src/class/mysqlcppapi/row/subdir.mk -include src/class/mysqlcppapi/query_results/subdir.mk -include src/class/mysqlcppapi/query/subdir.mk -include src/class/mysqlcppapi/fields/subdir.mk -include src/class/mysqlcppapi/exceptions/subdir.mk -include src/class/mysqlcppapi/datetime/subdir.mk -include objects.mk ifneq ($(MAKECMDGOALS),clean) ifneq ($(strip $(C++_DEPS)),) -include $(C++_DEPS) endif ifneq ($(strip $(C_DEPS)),) -include $(C_DEPS) endif ifneq ($(strip $(CC_DEPS)),) -include $(CC_DEPS) endif ifneq ($(strip $(CPP_DEPS)),) -include $(CPP_DEPS) endif ifneq ($(strip $(CXX_DEPS)),) -include $(CXX_DEPS) endif ifneq ($(strip $(C_UPPER_DEPS)),) -include $(C_UPPER_DEPS) endif endif -include ../makefile.defs # Add inputs and outputs from these tool invocations to the build variables # All Target all: vlogd # Tool invocations vlogd: $(OBJS) $(USER_OBJS) @echo 'Building target: $@' @echo 'Invoking: GCC C++ Linker' g++ -L/usr/lib64/mysql -L../../boost_1_42_0/lib/ -o"vlogd" $(OBJS) $(USER_OBJS) $(LIBS) @echo 'Finished building target: $@' @echo ' ' # Other Targets clean: -$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) vlogd -@echo ' ' .PHONY: all clean dependents .SECONDARY: -include ../makefile.targets
################################################################################ # Automatically-generated file. Do not edit! ################################################################################ USER_OBJS := LIBS := -lmysqlclient -lboost_regex
Проблемы с boost в Ubuntu
Доброго времени суток. Возникла проблема при сборке проекта под Ubuntu 16.04 и 14.04. При этом, под арчем (с версией boost 1.63) и под генту (с версией boost 1.56) проект собирается нормально.
Вот Makefile:
CC = g++ CFLAGS = -c -std=c++11 -Wall -Wextra LFLAGS = -lboost_system -lboost_thread -lpthread all: server client server: servermain.o daemon.o $(CC) $(LFLAGS) servermain.o daemon.o -o frtpdaemon servermain.o: server/main.cpp $(CC) $(CFLAGS) server/main.cpp -o servermain.o clog.o: server/clog.hpp $(CC) $(CFLAGS) server/clog.hpp -o clog.o parser.o: server/cparser.hpp $(CC) $(CFLAGS) server/cparser.hpp -o parser.o daemon.o: server/cdaemon.cpp server/cdaemon.h $(CC) $(CFLAGS) server/cdaemon.cpp -o daemon.o client: clientmain.o client.o $(CC) $(LFLAGS) -shared clientmain.o client.o -o libfrtpsrv.so clientmain.o: client/main.cpp $(CC) $(CFLAGS) -fpic client/main.cpp -o clientmain.o client.o: client/cclient.cpp client/cclient.h $(CC) $(CFLAGS) -fpic client/cclient.cpp -o client.o clean: rm *.o frtpdaemon libfrtpsrv.so
servermain.o: In function `__static_initialization_and_destruction_0(int, int)': main.cpp:(.text+0x1de): undefined reference to `boost::system::generic_category()' main.cpp:(.text+0x1ea): undefined reference to `boost::system::generic_category()' main.cpp:(.text+0x1f6): undefined reference to `boost::system::system_category()' servermain.o: In function `boost::asio::error::get_system_category()': main.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()' daemon.o: In function `__static_initialization_and_destruction_0(int, int)': cdaemon.cpp:(.text+0x16bb): undefined reference to `boost::system::generic_category()' cdaemon.cpp:(.text+0x16c7): undefined reference to `boost::system::generic_category()' cdaemon.cpp:(.text+0x16d3): undefined reference to `boost::system::system_category()' daemon.o: In function `boost::system::error_code::error_code()': cdaemon.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()' daemon.o: In function `boost::asio::detail::posix_signal_blocker::posix_signal_blocker()': cdaemon.cpp:(.text._ZN5boost4asio6detail20posix_signal_blockerC2Ev[_ZN5boost4asio6detail20posix_signal_blockerC5Ev]+0x64): undefined reference to `pthread_sigmask' daemon.o: In function `boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()': cdaemon.cpp:(.text._ZN5boost4asio6detail20posix_signal_blockerD2Ev[_ZN5boost4asio6detail20posix_signal_blockerD5Ev]+0x2d): undefined reference to `pthread_sigmask' collect2: error: ld returned 1 exit status
Boost в убунте установлен. Вместо -lboost_system и -lboost_thread пробовал указывать библиотеки явно, что все равно не привело ни к каким результатам. Кто-то сталкивался с таким?
Linking Boost Library in Linux
I am trying to build a project using Boost’s Asio and I am having some trouble. Initially, I tried to build the project without any additional libraries since everything is supposedly in the header files. The program I am trying to build looks like this:
#include #include #include int main()
make -k all Building target: HelloWorld Invoking: GCC C++ Linker g++ -o"HelloWorld" ./main.o ./main.o: In function `__static_initialization_and_destruction_0': /usr/include/boost_1_40_0/boost/system/error_code.hpp:205: undefined reference to `boost::system::get_system_category()' /usr/include/boost_1_40_0/boost/system/error_code.hpp:206: undefined reference to `boost::system::get_generic_category()' /usr/include/boost_1_40_0/boost/system/error_code.hpp:211: undefined reference to `boost::system::get_generic_category()' /usr/include/boost_1_40_0/boost/system/error_code.hpp:212: undefined reference to `boost::system::get_generic_category()' /usr/include/boost_1_40_0/boost/system/error_code.hpp:213: undefined reference to `boost::system::get_system_category()' ./main.o: In function `boost::asio::error::get_system_category()': /usr/include/boost_1_40_0/boost/asio/error.hpp:218: undefined reference to `boost::system::get_system_category()' ./main.o: In function `error_code': /usr/include/boost_1_40_0/boost/system/error_code.hpp:312: undefined reference to `boost::system::get_system_category()' ./main.o: In function `posix_tss_ptr': /usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:47: undefined reference to `pthread_key_create' ./main.o: In function `~posix_tss_ptr': /usr/include/boost_1_40_0/boost/asio/detail/posix_tss_ptr.hpp:61: undefined reference to `pthread_key_delete' ./main.o: In function `boost::asio::detail::posix_thread::join()': /usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:77: undefined reference to `pthread_join' ./main.o: In function `~posix_thread': /usr/include/boost_1_40_0/boost/asio/detail/posix_thread.hpp:69: undefined reference to `pthread_detach' collect2: ld returned 1 exit status make: *** [HelloWorld] Error 1 make: Target `all' not remade because of errors.
It appeared that I needed the system library. So, I followed the directions on the Getting Started guide found here, which gave me a bunch of libraries located in /usr/include/boost_1_40_0/stage/lib. Among them was libboost_system.a. Thus, I attempted to compile with:
-I /usr/include/boost_1_40_0 -L /usr/include/boost_1_40_0/stage/lib -l libboost_system
make -k all Building target: HelloWorld Invoking: GCC C++ Linker g++ -L/usr/lib -L/usr/include/boost_1_40_0/stage/lib -o"HelloWorld" ./main.o -llibboost_system /usr/bin/ld: cannot find -llibboost_system collect2: ld returned 1 exit status make: *** [HelloWorld] Error 1 make: Target `all' not remade because of errors.
I’m not sure why, but it can’t seem to identify the library or any of the others that I try. What might I be doing incorrectly? Thanks in advance!
Cmake doesn’t find Boost
I’m trying to configure a project using CMake, but it fails to find Boost libraries even though they are in the specified folder. I have specified Boost_INCLUDE_DIR , Boost_LIBRARYDIR and BOOST_ROOT , but I still get an error saying that CMake is not able to find Boost. What could be the reason of such error?
Some versions of Boost use the flag Boost_INCLUDE_DIR and others use the flag Boost_INCLUDEDIR (without the underscore). You can check the right one for your case by reading the FindBoost.cmake file, under path-to-cmake/Modules/FindBoost.cmake
16 Answers 16
Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR , BOOST_LIBRARYDIR and BOOST_ROOT automatically. Do something like this in CMakeLists.txt :
FIND_PACKAGE(Boost) IF (Boost_FOUND) INCLUDE_DIRECTORIES($) ADD_DEFINITIONS( "-DHAS_BOOST" ) ENDIF()
If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:
SET(CMAKE_INCLUDE_PATH $ "C:/win32libs/boost") SET(CMAKE_LIBRARY_PATH $ "C:/win32libs/boost/lib")
Of course, those two lines have to be before the FIND_PACKAGE(Boost) in CMakeLists.txt .
Maybe this has changed in newer versions of cmake, but here’s the reference docs: cmake.org/cmake/help/v3.0/module/FindBoost.html
@IhorKaharlichenko, but BOOST_ROOT should be BOOST_ROOT. wonderful ! Let me try with all cases, camel case, all caps, with underscores, without underscores .
There is more help available by reading the FindBoost.cmake file itself. It is located in your ‘Modules’ directory.
A good start is to set(Boost_DEBUG 1) — this will spit out a good deal of information about where boost is looking, what it’s looking for, and may help explain why it can’t find it.
It can also help you to figure out if it is picking up on your BOOST_ROOT properly.
FindBoost.cmake also sometimes has problems if the exact version of boost is not listed in the Available Versions variables. You can find more about this by reading FindBoost.cmake .
Lastly, FindBoost.cmake has had some bugs in the past. One thing you might try is to take a newer version of FindBoost.cmake out of the latest version of CMake, and stick it into your project folder alongside CMakeLists.txt — then even if you have an old version of boost, it will use the new version of FindBoost.cmake that is in your project’s folder.