发新话题
打印

连接出错

连接出错

用cygwin的# X4 J: H) _& @
g++ thread1.cpp -I /usr/include/boost-1_33_1
复制内容到剪贴板
代码:
错误提示如下:
/cygdrive/c/DOCUME~1/ZWENQI~1/LOCALS~1/Temp/ccpmdPK4.o:thread1.cpp:(.text+0x1c5): undefined reference to `boost::thread::thread(boost::function0<void, std::allocator<boost::function_base> > const&)'
/cygdrive/c/DOCUME~1/ZWENQI~1/LOCALS~1/Temp/ccpmdPK4.o:thread1.cpp:(.text+0x21b): undefined reference to `boost::thread::join()'
/cygdrive/c/DOCUME~1/ZWENQI~1/LOCALS~1/Temp/ccpmdPK4.o:thread1.cpp:(.text+0x22d): undefined reference to `boost::thread::~thread()'
/cygdrive/c/DOCUME~1/ZWENQI~1/LOCALS~1/Temp/ccpmdPK4.o:thread1.cpp:(.text+0x25f): undefined reference to `boost::thread::~thread()'
collect2: ld returned 1 exit status
      

TOP

编译是没有问题的,可以生成.o文件,但连接就出现错误
# H4 f$ T' r+ G
$ G* h3 \1 D! ]- t1 Tg++ -c thread1.cpp -o thread -I /usr/include/boost-1_33_1
) X  u8 d7 R2 B
8 k! S0 ^+ k/ Z, M( W; B" w+ sld thread1.o: i: H8 j; i1 A8 y/ H  `. l  o& G
出错提示:
复制内容到剪贴板
代码:
ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000
thread1.o :thread1.cpp: (.text+0xd) : undefined reference to `std::string::size() const'
thread1.o :thread1.cpp: (.text+0x60) : undefined reference to `std::string::perator[](unsigned int) const'
thread1.o :thread1.cpp: ( .text+0x9f) : undefined reference to `std::string::perator[](unsigned int) const'
thread1.o :thread1.cpp: (.text+0xce): undefined reference to `std::string:perator[](unsigned int) const'
thread1.o :thread1.cpp: (.text+0x111): undefined reference to `std::cout'
thread1.o :thread1.cpp: (.text+0x116): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
thread1.o :thread1.cpp: (.text+0x11e): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
thread1.o :thread1.cpp.text+0x126): undefined reference to `std:stream: perator<<(std:stream& (*)(std:stream&))'
thread1.o :thread1.cpp: (.text+0x159): undefined reference to `_alloca'
thread1.o :thread1.cpp: (.text+0x160): undefined reference to `__gxx_personality_sj0'
thread1.o :thread1.cpp: (.text+0x185): undefined reference to `_Unwind_SjLj_Register'
thread1.o :thread1.cpp: (.text+0x18a): undefined reference to `__main'
thread1.o :thread1.cpp: (.text+0x1c5): undefined reference to `boost::thread::thread(boost::function0<void, std::allocator<boost::function_base> > const&)'
thread1.o :thread1.cpp: (.text+0x1f7): undefined reference to `_Unwind_SjLj_Resume'
thread1.o :thread1.cpp: (.text+0x21b): undefined reference to `boost::thread::join()'
thread1.o :thread1.cpp: (.text+0x22d): undefined reference to `boost::thread::~thread()'
thread1.o :thread1.cpp: (.text+0x25f): undefined reference to `boost::thread::~thread()'
thread1.o :thread1.cpp: (.text+0x277): undefined reference to `_Unwind_SjLj_Resume'
thread1.o :thread1.cpp: (.text+0x282): undefined reference to `_Unwind_SjLj_Unregister'
thread1.o :thread1.cpp: (.text+0x2af): undefined reference to `std::ios_base::Init::Init()'
thread1.o :thread1.cpp: (.text+0x2ca): undefined reference to `std::ios_base::Init::~Init()'
thread1.o :thread1.cpp.text$_ZN5boost6detail8function15functor_managerIPFvvESaINS_13function_baseEEE6manageENS1_11any_pointerENS1_30functor_manager_operation_typeE[__ZN5boost6detail8function15functor_managerIPFvvESaINS_13function_baseEEE6manageENS1_11any_pointerENS1_30functor_manager_operation_typeE]+0x34): undefined reference to `strcmp'
thread1.o :thread1.cpp: (.rdata$_ZTIPFvvE[__ZTIPFvvE]+0x0): undefined reference to `vtable for __cxxabiv1::__pointer_type_info'
thread1.o:thread1.cpp: (.rdata$_ZTIFvvE[__ZTIFvvE]+0x0): undefined reference to `vtable for __cxxabiv1::__function_type_info'

      

TOP

复制内容到剪贴板
代码:
//thread1.cpp

#include <boost/thread/thread.hpp>
#include <iostream>

void hello()
{
                std::cout <<
                "Hello world, I'm a thread!"
                << std::endl;
}

int main(int argc, char* argv[])
{
                boost::thread thrd(&hello);
                thrd.join();
                return 0;
}
      

TOP

g++ thread1.cpp -I /usr/include/boost-1_33_1 ) X, Q9 C( h( G1 z# ~' A
6 B: z) |0 g# F- |9 L; s6 Q# d
还需要加入thread的连接库,假定在usr/libs下,需要的库是thread
. x8 [( Z0 h1 D6 Q7 ?L :指定库的目录) [; f* M5 ~- Z6 Q6 `% q) l9 _6 l
l :指定库名
$ ~% `# L$ A. W ( `6 w3 R' t, m+ P' F/ ^, E
g++ thread1.cpp -I /usr/include/boost-1_33_1 -Lusr/libs -lthread      
[font=黑体][size=7][color=red]革命命运[/color][/size][/font]

TOP

发新话题