Tôi đang học Boost và gặp sự cố khi tạo tệp. Đây là makefile cơ bản của tôi:Bao gồm các thư viện tăng cường để tạo các tệp
accesstimer: acctime.o btimer.o
g++ acctime.o btimer.o -o accesstimer
acctime.o: acctime.cpp btimer.h
g++ -c acctime.cpp
bentimer.o: btimer.cpp btimer.h
g++ -c btimer.cpp
Khi acctime.cpp không có các yếu tố thúc đẩy hệ thống tập tin trong đó m này, tập tin ake hoạt động tốt. Ngay sau khi tôi thêm các yếu tố hệ thống tập tin tăng cường, tôi rõ ràng cần tham chiếu đến việc tăng libray trong tệp tạo ra đây là nơi tôi gặp sự cố.
Các dòng sau làm việc cho một bộ sưu tập duy nhất:
g++ -I /usr/local/boost/boost_1_39_0 boosttest1.cpp -o bt1 /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a
Bây giờ tôi đang cố gắng để hội nhập này vào làm cho tập tin. Tôi đã thử nhiều dựa trên những thông tin tôi có thể tìm thấy trên web nhưng không ai đang làm việc này là mới nhất của tôi:
accesstimer: acctime.o bentimer.o
g++ acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c -I /usr/local/boost/boost_1_39_0 acctime.cpp /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Đáng tiếc là nó stlill không thể tìm thấy các thư viện Boost, bất cứ ai có thể giúp đỡ? nhờ
Sau khi đọc những lời khuyên của những người đã trả lời bây giờ tôi đã nhận điều này:
accesstimer: acctime.o bentimer.o
g++ -L /usr/local/boost/boost_1_39_0 acctime.o /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Nhưng điều này vẫn thất bại trong việc liên kết.
Đây là thông báo lỗi tôi nhận được: (! Cảm ơn nhiều đánh giá cao)
g++ -L /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a /usr/local/boost/boost_1_39_0/stage/lib/libboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
acctime.o: In function boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
acctime.cpp:(.text._ZN5boost10filesystem6existsINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EEbE4typeERKS7_[boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, bool>::type boost::filesystem::exists<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)]+0x26): undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int&)'
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
Sau orsogufo của lời khuyên bây giờ có này:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Nhìn tốt hơn, nhưng vẫn có thể không hoàn toàn tìm thư viện:
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -llibboost_filesystem-gcc41-mt.a -llibboost_system-gcc41-mt.a acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt.a
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
Tôi đã kiểm tra kỹ vị trí đó và thư viện chắc chắn là: /usr/local/boost/boost_1_39_0/stage/lib/libboost_filesystem-gcc41-mt.a
vẫn không có niềm vui, usimg này ngay bây giờ:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0 -lboost_filesystem-gcc41-mt acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Bắt:
g++ -L/usr/local/boost/boost_1_39_0/stage/lib/ -llibboost_filesystem-gcc41-mt acctime.o bentimer.o -o accesstimer
/usr/bin/ld: cannot find -llibboost_filesystem-gcc41-mt
collect2: ld returned 1 exit status
make: *** [accesstimer] Error 1
Đó là làm việc với điều này:
accesstimer: acctime.o bentimer.o
g++ -L/usr/local/boost/boost_1_39_0/stage/lib -lboost_filesystem acctime.o bentimer.o -o accesstimer
acctime.o: acctime.cpp bentimer.h
g++ -I /usr/local/boost/boost_1_39_0 -c acctime.cpp
bentimer.o: bentimer.cpp bentimer.h
g++ -c bentimer.cpp
Cảm ơn tất cả sự giúp đỡ của bạn
Ông có thể xin vui lòng gửi thông báo lỗi bạn đang nhận được? –
Khi bạn liên kết các thư viện với cờ -l, bạn luôn bỏ qua "lib" hàng đầu. Vì vậy, liên kết libm.a là -lm, libboost là -lboost, v.v. –