我已经增强了信号库,构建于:
./b2 address-model=32 link=static --build-type=complete --with-signals --layout=tagged
简单的代码:
#include <iostream>
#include "boost/signal.hpp"
void onSignal() {
std::cout << "Hello from slot" << std::endl;
}
int main() {
boost::signal<void()> sig;
sig.connect(&onSignal);
sig();
return 0;
}
CmakeLists.txt:
project(test)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -static")
aux_source_directory(. SRC_LIST)
include_directories(/home/koshchiy/dev/boost/boost_1_51_0)
link_directories(/home/koshchiy/dev/boost/boost_1_51_0/stage)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} libboost_signals-mt-s.a)
它构建没有错误,但是在运行时,我得到了:
bash: ./test: No such file or directory
似乎是,cmake 产生动态链接而不是静态链接:
koshchiy@koshchiy-lin-NB:~/dev/projects/test/test-build-release$ ldd test
linux-gate.so.1 => (0xf778b000)
libstdc++.so.6 => /usr/lib32/libstdc++.so.6 (0xf768e000)
libc.so.6 => /lib32/libc.so.6 (0xf74e7000)
libm.so.6 => /lib32/libm.so.6 (0xf74bc000)
/usr/lib/libc.so.1 => /lib/ld-linux.so.2 (0xf778c000)
libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf749e000)
没有 cmake 的构建似乎没问题:
g++ -static main.cpp -o test -I... -l...
我正在使用 ubuntu 12.04 x64 和 g++-4.7 编译器。