0

I am using eclipse luna on win 7.
Here is my program.

#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

int main(int argc, char* argv[]){
    // All programs that use asio need to have at least one io_service object
    boost::asio::io_service io;
    // sets the timer to expire 5 seconds from now
    boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
    t.wait();

    std::cout << "Hello, world!\n";

    return 0;

}

Here is my command line code

g++ -I"C:\Users\Documents\Lib\boost_1_57_0\boost_1_57_0" -O0 -g3 -Wall -c -fmessage-length=0 -lboost_filesystem -lboost_system -lboost_libraryname -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Invoking: Cross G++ Linker
g++  -o "002_TimerSynchronously"  ./main.o   

Error

C:/Users/SulfredLee/Documents/Lib/boost_1_57_0/boost_1_57_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Users/SulfredLee/Documents/Lib/boost_1_57_0/boost_1_57_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Users/SulfredLee/Documents/Lib/boost_1_57_0/boost_1_57_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'

Anyone knows how to fix it?
Thank you very much

Reference:
undefined reference to boost::system::system_category() when compiling
How do I troubleshoot boost library/header inclusion via autoconf/automake?

Community
  • 1
  • 1
sflee
  • 1,659
  • 5
  • 32
  • 63

1 Answers1

1

The libraries should be present in the second command line when the linking takes place. Please be also careful and list the libraries after the object file.

Manuel Barbe
  • 2,104
  • 16
  • 21
  • g++ -I"C:\Users\Documents\Lib\boost_1_57_0\boost_1_57_0" -O0 -g3 -Wall -c -fmessage-length=0 -lboost_filesystem -lboost_system -lboost_libraryname -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
    g++ -L"C:\Users\Documents\Lib\boost_1_57_0\boost_1_57_0" -o "002_TimerSynchronously" ./main.o
    This time I did this but still get the errors.
    – sflee Feb 23 '15 at 06:32
  • g++ -o "002_TimerSynchronously" ./main.o -L"C:\Users\Documents\Lib\boost_1_57_0\boost_1_57_0" -lboost_filesystem -lboost_system – Manuel Barbe Feb 23 '15 at 06:38
  • Now the errors are: g++ -L"C:\Users\Documents\Lib\boost_1_57_0\boost_1_57_0" -lboost_filesystem -lboost_system -o "002_TimerSynchronously" ./main.o c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lboost_filesystem c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lboost_system – sflee Feb 23 '15 at 06:45
  • 1
    Are you possibly missing a "SulfredLee" in your boost installation path "C:\Users\SulfredLee\Documents\..."? In your post it appears to be the installation directory. – Manuel Barbe Feb 23 '15 at 06:52