g++ -l flag in Eclipse

Does anyone know how to add an -l flag to my build in Eclipse Kepler?

My build requires the following commands:

  
$ g++ sniff.cpp -o sniff -lcrafter  

However, currently when Eclipse builds my project, the only commands it receives are:

  
g++  -o "sniffer_crafter"  ./src/sniffer_crafter.o    

From this I get these error messages:

  
13:24:54 **** Incremental Build of configuration Debug for project sniffer_crafter ****  
make all   
Building target: sniffer_crafter  
Invoking: GCC C++ Linker  
g++  -o "sniffer_crafter"  ./src/sniffer_crafter.o     
./src/sniffer_crafter.o: In function `main':  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:22: undefined reference to `Crafter::RawLayer::RawLayer(char const*)'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:23: undefined reference to `Crafter::RawLayer::RawLayer(char const*)'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:26: undefined reference to `Crafter::operator/(Crafter::Layer const&, Crafter::Layer const&)'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:29: undefined reference to `Crafter::Packet::Print() const'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:30: undefined reference to `Crafter::Packet::HexDump(std::ostream&)'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:31: undefined reference to `Crafter::Packet::RawString(std::ostream&)'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:34: undefined reference to `Crafter::Packet::Send(std::string const&)'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:26: undefined reference to `Crafter::Packet::~Packet()'  
/home/gryzynger/Documents/cpp_workspace/sniffer_crafter/Debug/../src/sniffer_crafter.cpp:26: undefined reference to `Crafter::Packet::~Packet()'  
./src/sniffer_crafter.o: In function `Crafter::RawLayer::~RawLayer()':  
/usr/local/include/crafter/Protocols/RawLayer.h:80: undefined reference to `vtable for Crafter::RawLayer'  
/usr/local/include/crafter/Protocols/RawLayer.h:80: undefined reference to `Crafter::Layer::~Layer()'  
collect2: error: ld returned 1 exit status  
make: *** [sniffer_crafter] Error 1  
  
13:24:55 Build Finished (took 162ms)  

How can I resolve this? When I invoke the g++ complier from the terminal I don’t have any issues running the program.

in linux you can add additional libraries in the LDFLAGS section in the config.make file

Is there a way to add this through any of Eclipse’s interfaces though?

no, we don’t use the typical eclipse configuration since the projects are based on custom makefiles

Okay, for this then my current config.make file has for that section:

  
# PROJECT_LDFLAGS=-Wl,-rpath=./libs  

I would then just put:

  
# PROJECT_LDFLAGS=-Wl,-lfoo,-rpath=./libs  

Or is there a different syntax I should be using here?

the # in makefiles is a comment so you need to remove it, the other flags are not really needed:

  
  
PROJECT_LDFLAGS=-lfoo  
  

should do, if you need to add several libraries the separator is a space not a comma, like:

  
  
PROJECT_LDFLAGS=-lfoo -lbar  
  

the flags are the same you would pass to g++

1 Like

Thanks, that did the trick.