Ang*_*.47 1 c++ linux boost include
问题:目前我正在编译Ubuntu,但我的服务器正在运行Fedora/Redhat.Ubunutu使用boost 1.42和linux最新时刻是1.41.所以我决定下载boost lib并将其放在我工作区的文件夹中
这是目录结构
/workspace
/myprogram
/src
/main.cpp
/Debug
/main
/boost_1_42_0
/downloaded from boost.com
Run Code Online (Sandbox Code Playgroud)
在我的main.cpp中,我有这个代码
#include "../../boost_1_42_0/boost/regex.hpp"
Run Code Online (Sandbox Code Playgroud)
这是偶然的还是我在错误的树上咆哮.我试图编译它,但它失败了(ofcourse)有13个错误
如果我错过了一些信息请求它,我试着提供它
制作文件(我的程序称为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
Run Code Online (Sandbox Code Playgroud)
对象文件
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
USER_OBJS :=
LIBS := -lmysqlclient -lboost_regex
Run Code Online (Sandbox Code Playgroud)
如果您gcc只使用指定正确的包含路径和链接路径,则无需包含使用完整路径
gcc -I../../boost_1_42_0/ myprogram.cpp -L../../boost_1_42_0/lib -lboostXYZ
Run Code Online (Sandbox Code Playgroud)
因此,#include <boost/...>首先在本地boost中搜索所有头文件和库.
编辑关注
评论中的问题.
默认情况下,-l将搜索.so库.所以,如果升压与如建立libboost_regex.so和liboost_regex.a,则默认情况下你会链接到.so.如果您已链接到.so工作服务器上,则需要拥有这些库的正确版本(可以安装几个boost版本).
如果要隐式链接到静态版本,请使用完整路径
gcc .... ../../boost_1_42_0/lib/libboost_regex.a
Run Code Online (Sandbox Code Playgroud)
要么
gcc ... -Wl,-Bstatic -L../../boost_1_42_0/lib -lboost_regex -Wl,-Bdynamic
Run Code Online (Sandbox Code Playgroud)
或(在较新版本中ld)
gcc ... -L../../boost_1_42_0/lib -l:libboost_regex.a
Run Code Online (Sandbox Code Playgroud)
使用带ldd命令的二进制文件,您可以看到它的共享库依赖项,并检查其中是否存在增强库
ldd ./yourapp
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1048 次 |
| 最近记录: |