I'd like to use Apache log4cxx and am running into a problem. I'm running on Debian 8 and installed log4cxx using
apt-get install liblog4cxx10-dev
I have embedded one of the code snippets in the Documentation Page into the code below:
#include <log4cxx/logger.h>
#include <math.h>
int main(int argc, char* argv[]) {
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("com.foo"));
int i = 10;
const char* region = "World";
LOG4CXX_INFO(logger, "Simple message text.")
LOG4CXX_INFO(logger, "Hello, " << region)
LOG4CXX_DEBUG(logger, L"Iteration " << i)
LOG4CXX_DEBUG(logger, "e^10 = " << std::scientific << exp(10.0))
LOG4CXX_WARN(logger, L"" << i << L" is the number of the iteration.")
return 0;
}
When compiling with Eclipse CDT (gcc 5.3.0 built from source) I get the following linker errors:
make all
Building file: ../src/tester.cxx
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/tester.d" -MT"src/tester.o" -o "src/tester.o" "../src/tester.cxx"
Finished building: ../src/tester.cxx
Building target: logtest
Invoking: GCC C++ Linker
g++ -L/usr/lib/x86_64-linux-gnu -o "logtest" ./src/tester.o -llog4cxx
./src/tester.o: In function `main':
/home/andand/workspace/logtest/Debug/../src/tester.cxx:9: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](log4cxx::helpers::CharMessageBuffer&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:9: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:10: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](log4cxx::helpers::CharMessageBuffer&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:10: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:11: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:11: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:12: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](std::ostream&)'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:12: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, log4cxx::spi::LocationInfo const&) const'
/home/andand/workspace/logtest/Debug/../src/tester.cxx:13: undefined reference to `log4cxx::helpers::MessageBuffer::str[abi:cxx11](std::basic_ostream<wchar_t, std::char_traits<wchar_t> >&)'
makefile:45: recipe for target 'logtest' failed
/home/andand/workspace/logtest/Debug/../src/tester.cxx:13: undefined reference to `log4cxx::Logger::forcedLog(log4cxx::helpers::ObjectPtrT<log4cxx::Level> const&, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, log4cxx::spi::LocationInfo const&) const'
collect2: error: ld returned 1 exit status
make: *** [logtest] Error 1
I double checked where apt installed the libraries:
root#starsim-dev:/home/andand# find / -name *log4cxx*
/usr/lib/x86_64-linux-gnu/liblog4cxx.a
/usr/lib/x86_64-linux-gnu/liblog4cxx.so.10.0.0
/usr/lib/x86_64-linux-gnu/liblog4cxx.so.10
/usr/lib/x86_64-linux-gnu/liblog4cxx.so
/usr/lib/x86_64-linux-gnu/pkgconfig/liblog4cxx.pc
/usr/include/log4cxx
/usr/include/log4cxx/private/log4cxx_private.h
/usr/include/log4cxx/log4cxx.h
/usr/share/doc/liblog4cxx10
/usr/share/doc/liblog4cxx10-dev
/usr/share/lintian/overrides/liblog4cxx10
/usr/share/lintian/overrides/liblog4cxx10-dev
/var/cache/apt/archives/liblog4cxx10-dev_0.10.0-4_amd64.deb
/var/cache/apt/archives/liblog4cxx10_0.10.0-4_amd64.deb
/var/lib/dpkg/info/liblog4cxx10:amd64.postinst
/var/lib/dpkg/info/liblog4cxx10:amd64.shlibs
/var/lib/dpkg/info/liblog4cxx10-dev.list
/var/lib/dpkg/info/liblog4cxx10:amd64.list
/var/lib/dpkg/info/liblog4cxx10:amd64.md5sums
/var/lib/dpkg/info/liblog4cxx10:amd64.postrm
/var/lib/dpkg/info/liblog4cxx10-dev.md5sums
The documentation on Apache's website isn't entirely clear what other library dependencies exist. Does anybody have some insight into what I'm missing?
I ran into the same set of linker errors trying to use log4cxx on Ubuntu 18.04. I was able to get their code snippets to work - including the one above - by adding the following additional Apache libs to my MakeFile
LIBS+= -llog4cxx -laprutil-1 -lapr-1
Make sure to list them in the above order.
Related
I am trying to compile this code in CodeBlocks
#include <boost/filesystem.hpp>
#include <iostream>
using namespace boost::filesystem;
int main()
{
if ( !boost::filesystem::exists( "myfile.txt" ) )
{
std::cout << "Can't find my file!" << std::endl;
}
}
With this compile flags:
g++.exe -Wall -fexceptions -g -O3 -pedantic-errors -Wall -std=c++0x -lboost_system -IC:\Users\moe\Desktop\boost_1_67_0 -c C:\Users\moe\Desktop\oo\main.cpp -o obj\Debug\main.o
But I always receive this error:
boost::system::generic_category()
this is the error log, that i receive when i compile the code:
Untitled4.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:733: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:736: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:748: undefined reference to `boost::system::generic_category()'
Untitled4.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:703: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
Untitled4.o: In function `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path::codecvt()'
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, int> const&)'
Untitled4.o: In function `boost::filesystem::exists(boost::filesystem::path const&)':
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/operations.hpp:446: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
collect2.exe: error: ld returned 1 exit status
Put the libraries at the end of the linker command line:
Why does the order of '-l' option in gcc matter?
Since your erro log also contained these:
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path::codecvt()'
It is clear that you also lack -lboost_filesystem.
So there is no use to just add -lboost_system to the g++ command.
You can add -lboost_system -lboost_filesystem to your g++ command.
I am having an issue with compiling one of the sample (example codes) for a C++ based jwt library from a github project: jwt-cpp
I cloned it and compiled it using the steps provided in the README file, which seemed successful.
After that I did a ldconfig.
Now, I am trying to build the example code.
#include <iostream>
#include "jwt/jwt_all.h"
using json = nlohmann::json;
int main()
{
// Setup a signer
HS256Validator signer("secret!");
// Create the json payload that expires 01/01/2017 # 12:00am (UTC)
json payload = {{"sub", "subject"}, {"exp", 1483228800}};
// Let's encode the token to a string
auto token = JWT::Encode(signer, payload);
std::cout << token << std::endl;
}
I compile this with a command on terminal, which says:
g++ -std=c++11 \
-I/usr/local/include \
-I/usr/local/include \
/usr/local/lib/libjwt.a \
/usr/local/lib/libcrypto.a \
sign.cpp -o sign
And it results in following error:
/tmp/ccX4ghoR.o: In function `main':
sign.cpp:(.text+0x24e): undefined reference to
JWT::Encode(MessageSigner const&, nlohmann::basic_json<std::map,
std::vector, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, bool, long, unsigned long, double,
std::allocator, nlohmann::adl_serializer> const&,
nlohmann::basic_json<std::map, std::vector,
std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, bool, long, unsigned long, double,
std::allocator, nlohmann::adl_serializer>)'
/tmp/ccX4ghoR.o: In function
`HS256Validator::HS256Validator(std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&)': sign.cpp:(.text._ZN14HS256ValidatorC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN14HS256ValidatorC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x21): undefined reference to `EVP_sha256' sign.cpp:(.text._ZN14HS256ValidatorC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN14HS256ValidatorC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x5f): undefined reference to `HMACValidator::HMACValidator(std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, evp_md_st
const*, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'
/tmp/ccX4ghoR.o:
(.rodata._ZTV14HS256Validator[_ZTV14HS256Validator]+0x20): undefined
reference to `HMACValidator::Verify(nlohmann::basic_json<std::map,
std::vector, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, bool, long, unsigned long, double,
std::allocator, nlohmann::adl_serializer> const&, unsigned char
const*, unsigned long, unsigned char const*, unsigned long) const'
/tmp/ccX4ghoR.o:
(.rodata._ZTV14HS256Validator[_ZTV14HS256Validator]+0x28): undefined
reference to `HMACValidator::toJson[abi:cxx11]() const'
/tmp/ccX4ghoR.o:
(.rodata._ZTV14HS256Validator[_ZTV14HS256Validator]+0x38): undefined
reference to `MessageValidator::Accepts(nlohmann::basic_json<std::map,
std::vector, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >, bool, long, unsigned long, double,
std::allocator, nlohmann::adl_serializer> const&) const'
/tmp/ccX4ghoR.o:
(.rodata._ZTV14HS256Validator[_ZTV14HS256Validator]+0x40): undefined
reference to `HMACValidator::Sign(unsigned char const*, unsigned long,
unsigned char*, unsigned long*) const'
/tmp/ccX4ghoR.o: In function `HS256Validator::~HS256Validator()':
sign.cpp:
(.text._ZN14HS256ValidatorD2Ev[_ZN14HS256ValidatorD5Ev]+0x20):
undefined reference to `HMACValidator::~HMACValidator()'
/tmp/ccX4ghoR.o:
(.rodata._ZTI14HS256Validator[_ZTI14HS256Validator]+0x10): undefined
reference to `typeinfo for HMACValidator'
collect2: error: ld returned 1 exit status
What have I tried:
I have read through these questions to know what I might be doing wrong:
How to use libraries and compile C file using external library from linux terminal, Although second question is specifically for C and not C++, the problem there and the solution is applicable to C++ as well.
I have also tried variants of command line compilation such as,
g++ -std=c++11 \
-I/usr/local/include \
-I/usr/local/include \
-L/usr/local/lib/ \
-lcrypto -ljwt \
sign.cpp -o sign
I am familiar with the fact that when I do a -lfoo, the linker tries to find a libfoo.a at the location provided with -L option.
I have confirmed that the options that are used for compilation contains what they should.
For -I options:
I can see jwt and openssl directories in /usr/local/include
For -L options:
I can see libjwt.a, libssl.a, libcrypto.a, libssl.so, etc at /usr/local/lib/
Question:
What am I doing wrong to compile this example?
You're gonna kick yourself when I tell you the issue.
Put the source file, sign.cpp before the library declarations in your program:
g++ -std=c++11 -I/usr/local/include -L/usr/local/lib sign.cpp -lcrypto -ljwt -o sign
The reason being is that the unix linker doesn't look backwards in the command line to resolve dependencies. There's a few command line switches (e.g. --start-group and --end-group) that will adjust this behavior, but the above will get you unblocked for now. More details here.
In the above example, I took the liberty of removing the duplicated INCLUDE path arguments. You probably don't even need the -I/usr/local/include or -L/usr/local/lib part because that's typically already in the standard compiler path.
i am using proxygen library by facebook to build a simple client example . in a directory i have two object files how do i link them :
i am using:
g++ -std=c++11 -o my_echo CurlClientMain.o CurlClient.o -lproxygenhttpserver -lfolly -lglog -lgflags -pthread
i think i ma missing some linker flag like -lgflags in above example. maybe after including some -someflag will help out compilation . how do i know what all possilble library flags are posiible like the one they have used -lproxyhttpserver.
In short where is all these libs defined or located. i am using ubuntu.
Here is my error message
In function `main':
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::HTTPConnector(proxygen::HTTPConnector::Callback*, folly::HHWheelTimer*)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:102: undefined reference to `proxygen::HTTPConnector::connect(folly::EventBase*, folly::SocketAddress const&, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::map<folly::AsyncSocket::OptionKey, int, std::less<folly::AsyncSocket::OptionKey>, std::allocator<std::pair<folly::AsyncSocket::OptionKey const, int> > > const&, folly::SocketAddress const&)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::~HTTPConnector()'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:99: undefined reference to `proxygen::HTTPConnector::connectSSL(folly::EventBase*, folly::SocketAddress const&, std::shared_ptr<folly::SSLContext> const&, ssl_session_st*, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::map<folly::AsyncSocket::OptionKey, int, std::less<folly::AsyncSocket::OptionKey>, std::allocator<std::pair<folly::AsyncSocket::OptionKey const, int> > > const&, folly::SocketAddress const&, std::string const&)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::~HTTPConnector()'
CurlClient.o: In function `CurlService::CurlClient::connectSuccess(proxygen::HTTPUpstreamSession*)':
/home/kshitij/proxygen/httpclient/samples/curl/CurlClient.cpp:69: undefined reference to `proxygen::HTTPUpstreamSession::newTransaction(proxygen::HTTPTransactionHandler*)'
collect2: error: ld returned 1 exit status
kshitij#forgetit:~/proxygen/httpclient/samples/curl$ g++ -std=c++11 -o my_echo CurlClientMain.o CurlClient.o -lproxygenhttpserver -lfolly -lglog -lgflags -pthread
CurlClientMain.o: In function `main':
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::HTTPConnector(proxygen::HTTPConnector::Callback*, folly::HHWheelTimer*)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:102: undefined reference to `proxygen::HTTPConnector::connect(folly::EventBase*, folly::SocketAddress const&, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::map<folly::AsyncSocket::OptionKey, int, std::less<folly::AsyncSocket::OptionKey>, std::allocator<std::pair<folly::AsyncSocket::OptionKey const, int> > > const&, folly::SocketAddress const&)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::~HTTPConnector()'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:99: undefined reference to `proxygen::HTTPConnector::connectSSL(folly::EventBase*, folly::SocketAddress const&, std::shared_ptr<folly::SSLContext> const&, ssl_session_st*, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::map<folly::AsyncSocket::OptionKey, int, std::less<folly::AsyncSocket::OptionKey>, std::allocator<std::pair<folly::AsyncSocket::OptionKey const, int> > > const&, folly::SocketAddress const&, std::string const&)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::~HTTPConnector()'
CurlClient.o: In function `CurlService::CurlClient::connectSuccess(proxygen::HTTPUpstreamSession*)':
/home/kshitij/proxygen/httpclient/samples/curl/CurlClient.cpp:69: undefined reference to `proxygen::HTTPUpstreamSession::newTransaction(proxygen::HTTPTransactionHandler*)'
collect2: error: ld returned 1 exit status
how do i know what all possilble library flags are posiible like the one they have used -lproxyhttpserver.
It depends on your compilation environment.
You appear to use the GNU compiler in linux. There is a tool to list all installed shared libraries:
ldconfig -p
You will get a list of lines like this
libpthread.so.0 (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib/x86_64-linux-gnu/libpthread.so.0
Remove the lib prefix and the extension .so.X and you get the name of the library. In this case it's pthread. To link with a libray use the option -lNAME. So, -lpthread in this example.
In short where is all these libs defined or located
The righthand part of the => is the full path to the library.
I am trying to test tesseract from opencv 3.0 using the test code from here
However, when I try to compile it, I get the following error
undefined reference to `cv::text::loadClassifierNM1(std::string const&)'
Any idea how I can fix this? Your help is much appreciated.
UPDATE 1
The complete error is
CMakeFiles/text_recog.dir/text_recog.o: In function `main':
text_recog.cpp:(.text+0x37b): undefined reference to `cv::text::loadClassifierNM1(std::string const&)'
text_recog.cpp:(.text+0x3bb): undefined reference to `cv::text::createERFilterNM1(cv::Ptr<cv::text::ERFilter::Callback> const&, int, float, float, float, bool, float)'
text_recog.cpp:(.text+0x42b): undefined reference to `cv::text::loadClassifierNM2(std::string const&)'
text_recog.cpp:(.text+0x44c): undefined reference to `cv::text::createERFilterNM2(cv::Ptr<cv::text::ERFilter::Callback> const&, float)'
text_recog.cpp:(.text+0x9c1): undefined reference to `cv::text::erGrouping(cv::_InputArray const&, cv::_InputArray const&, std::vector<std::vector<cv::text::ERStat, std::allocator<cv::text::ERStat> >, std::allocator<std::vector<cv::text::ERStat, std::allocator<cv::text::ERStat> > > >&, std::vector<std::vector<cv::Vec<int, 2>, std::allocator<cv::Vec<int, 2> > >, std::allocator<std::vector<cv::Vec<int, 2>, std::allocator<cv::Vec<int, 2> > > > >&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, int, std::string const&, float)'
text_recog.cpp:(.text+0xa95): undefined reference to `cv::text::OCRTesseract::create(char const*, char const*, char const*, int, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [text_recog] Error 1
make[1]: *** [CMakeFiles/text_recog.dir/all] Error 2
make: *** [all] Error 2
Does this help ?
It is a linker error. Look at an existing answer here
You need to compile it as g++ -o output input.cpp pkg-config opencv --cflags --libs if you are on Linux.
However if you have compiled OpenCV from source on Linux, use ldconfig to avoid linking issues.
You should use library -lopencv_text
LIBS += -lopencv_text
OR
g++ -o output input.cpp -lopencv_text
I have the following code which i m trying to compile:
#include <boost/filesystem/convenience.hpp>
#include <boost/foreach.hpp>
#include <boost/range.hpp>
#include <iostream>
int main(int, char**)
{
namespace bf = boost::filesystem;
BOOST_FOREACH(bf::path path,
boost::make_iterator_range(
bf::recursive_directory_iterator(bf::path("/home")),
bf::recursive_directory_iterator())) {
std::cout << path.string() << std::endl;
}
return 0;
}
My boost library is in /home/foo/include . and the include files are actually there.
when i run the following:
g++ -I/home/foo/include/ test.cc
I get the following error. how can i resolve this. what should i follow?
/tmp/ccvDmFNL.o(.text+0x502): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `boost::system::get_system_category()'
/tmp/ccvDmFNL.o(.text+0x51b): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `boost::system::get_generic_category()'
/tmp/ccvDmFNL.o(.text+0x534): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `boost::system::get_generic_category()'
/tmp/ccvDmFNL.o(.text+0x54d): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `boost::system::get_generic_category()'
/tmp/ccvDmFNL.o(.text+0x566): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `boost::system::get_system_category()'
/tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem24basic_directory_iteratorINS0_10basic_pathISsNS0_11path_traitsEEEE6m_initERKS4_+0x2e): In function `boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::m_init(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
: undefined reference to `boost::filesystem::detail::not_found_error()'
/tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem24basic_directory_iteratorINS0_10basic_pathISsNS0_11path_traitsEEEE6m_initERKS4_+0xbe): In function `boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::m_init(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)':
: undefined reference to `boost::filesystem::detail::dir_itr_first(void*&, void*&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::filesystem::file_status&, boost::filesystem::file_status&)'
/tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost6system10error_codeC1Ev+0x14): In function `boost::system::error_code::error_code()':
: undefined reference to `boost::system::get_system_category()'
/tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem24basic_directory_iteratorINS0_10basic_pathISsNS0_11path_traitsEEEE9incrementEv+0xde): In function `boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::increment()':
: undefined reference to `boost::filesystem::detail::dir_itr_increment(void*&, void*&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::filesystem::file_status&, boost::filesystem::file_status&)'
/tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem6statusINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EENS0_11file_statusEE4typeERKS7_+0x34): 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> >, boost::filesystem::file_status>::type boost::filesystem::status<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&)':
: undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::system::error_code&)'
/tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem6detail11dir_itr_impINS0_10basic_pathISsNS0_11path_traitsEEEED1Ev+0x1d): In function `boost::filesystem::detail::dir_itr_imp<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::~dir_itr_imp()':
: undefined reference to `boost::filesystem::detail::dir_itr_close(void*&, void*&)'
collect2: ld returned 1 exit status
EDIT:
Now i tried:
g++ -I/home/foo/include/ test.cc -lboost_system -lboost_filesystem
and get the following error:
/usr/bin/ld: cannot find -lboost_system
collect2: ld returned 1 exit status
I have the libboost_system-gcc34-1_38.so within
/home/foo/lib
how can I point to that?
from gcc man page:
-Ldir Add directory dir to the list of directories to be searched for -l.
So, is it that you are missing -L/home/foo/lib to the command line?
Your code compiled properly on my linux machine (Ubuntu 10.04, boost-filesystem 1.40) with the following command:
g++ test.cpp -lboost_filesystem
or
g++ test.cpp -lboost_system -lboost_filesystem
It gave me compile errors with g++ test.cpp -lboost_system
You must tell the compiler/linker where your libraries are as well, if they are not in the default location. For this you must use the -L flag to the compiler:
g++ -I/home/y/include/ test.cc -L/home/foo/lib -lboost_system -lboost_filesystem
Add -lboost_system (-lboost_system-mt if you're going to be threading) and -lboost_filesystem (-lboost_filesystem-mt if you're going to be threading) to the cmdline, before any input files.
Your boost libraries appear to be decorated with the suffix gcc34-1_38. Are you using gcc 3.4? Is your boost library on the library path? If not you may need to add the the path to your boost libraries using the -L flag to g++ or you can add the path to the LD_LIBRARY_PATH environment variable. In any case, you can link to your boost libraries by using -lboost_system-gcc34-1_38 and -lboost_filesystem-gcc34-1_38.