0

i stripped all classes from project, which left three errors like this:

error_code.hpp:222: undefined reference to `boost::system::generic_category()

using Netbeans IDE
clicked on file -> Project Properties -> Linker
next to Libraries, added libboost_system.so

which got rid of the three undefined reference to boost::system::generic_category()

now it gives:

CLEAN SUCCESSFUL (total time: 123ms)
cd '/home/michaeleric/NetBeansProjects/NNW'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/michaeleric/NetBeansProjects/NNW'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/nnw
make[2]: Entering directory `/home/michaeleric/NetBeansProjects/NNW'
mkdir -p build/Debug/GNU-Linux/_ext/d028d44d
rm -f "build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o.d" -o build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o ../../Desktop/NN_22_05_17/CGrid.cpp
mkdir -p dist/Debug/GNU-Linux
g++     -o dist/Debug/GNU-Linux/nnw build/Debug/GNU-Linux/_ext/d028d44d/CGrid.o -L/usr/include/boost -lboost_system
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux/nnw] Error 1
make[2]: Leaving directory `/home/michaeleric/NetBeansProjects/NNW'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/michaeleric/NetBeansProjects/NNW'
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 6s)

what does this error mean and how to fix?

class that rest requires

#include </usr/include/boost/thread/thread.hpp>
#include </usr/include/boost/thread/xtime.hpp>

#include </usr/include/boost/iostreams/write.hpp>

#define byte unsigned char
#define Thread boost::thread

class CGrid
{

    Thread* GetThread();

    bool SetThread(Thread* thread);

};

1 Answers1

0

If I compile this with

g++ test.cpp -lboost_system

I get the same linker error which is

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'

However, if I add an empty main function, it compiles fine. (I also replaced your ugly #define replacements with typedef.)

#include </usr/include/boost/thread/thread.hpp>
#include </usr/include/boost/thread/xtime.hpp>

#include </usr/include/boost/iostreams/write.hpp>

typedef unsigned char byte;
typedef boost::thread Thread;

class CGrid
{

    Thread* GetThread();

    bool SetThread(Thread* thread);

};

int main() {}

If this is meant to be an object file and main is in another translation unit, compile it as such with the -c parameter:

g++ -c test.cpp -lboost_system
Henri Menke
  • 10,705
  • 1
  • 24
  • 42
  • i did not get "undefined reference to `main'" error. And wondering why #define is ugly? – michael eric May 29 '17 at 05:51
  • @michaeleric Perhaps you have a different version of the linker. Regarding `#define` see [Are typedef and #define the same in c?](https://stackoverflow.com/questions/1666353/are-typedef-and-define-the-same-in-c) – Henri Menke May 29 '17 at 05:56