Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference in Linux makefile

I want to build my application under linux but i can't get my makefile to make it.
the problems are the static libraries I wan to link with. I get a lot of "undefined reference to" error messages like:

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

or

undefined reference to `cgicc::Cgicc::Cgicc(cgicc::CgiInput*)'

Here is my makefile:

CXX = gcc

INCL_CGICC = ../cgicc-3.2.9
INCL_OPENSSL = ../openssl-1.0.0e/include
INCL_LOG4CPLUS = ../log4cplus-1.0.4/include
INCL_BOOST = ../boost_1_46_1
INCLUDES = -I$(INCL_CGICC) -I$(INCL_OPENSSL) -I$(INCL_LOG4CPLUS) -I$(INCL_BOOST)

CXXFLAGS = -Wall -D_LINUX -DVERSNUM=2 -DVERSMAJOR=0 -DVERSMINOR=0 $(INCLUDES)

TARGET = myapp
OBJS = Main.o 

all: $(TARGET)
strip -s $<
mv -f $< release 

$(TARGET): $(OBJS)
$(CXX) -static -o $@ $(OBJS) \
            ../cgicc-3.2.9/cgicc/.libs/libcgicc.a \
            ../openssl-1.0.0e/libssl.a \
            ../openssl-1.0.0e/libcrypto.a \
            ../log4cplus-1.0.4/src/.libs/liblog4cplus.a \
            -ldl -lpthread

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $<

The problem is that I have no idea of makefiles. I just copied an existing one and tried to adjust it. Didn't seem to work, and I can't find an example makefile that includes static libraries.

like image 235
juergen d Avatar asked Sep 16 '11 07:09

juergen d


2 Answers

CXX = gcc

You're linking with gcc, rather than g++, so -lstdc++ is not linked in by default. Note that using gcc to compile C++ sources work just fine, since g++ is called implicitly in that case.

like image 135
Maister Avatar answered Nov 15 '22 06:11

Maister


If you have no clue about writing Makefiles, perhaps you should have a look at some of the Makefile generators, e.g. autotools, cmake etc. These are much easier to use in my opinion, and, once you master their use, much more powerful.

like image 30
arne Avatar answered Nov 15 '22 05:11

arne