I have been struggling to compile and link a C++ application that uses Boost libraries under a Ubuntu Server 11.01 64-bit edition.
At first not suceeding with prepackaged Boost libraries, I decided to compile it on my own. Boost compiles with no problem, but when I try to compile an application, linker starts spewing out errors as though no libraries were included.
builtinFunctions.o: In function `__static_initialization_and_destruction_0(int, int)':
builtinFunctions.cpp:(.text+0xcaab): undefined reference to `boost::system::generic_category()'
builtinFunctions.cpp:(.text+0xcab7): undefined reference to `boost::system::generic_category()'
builtinFunctions.cpp:(.text+0xcac3): undefined reference to `boost::system::system_category()'
builtinFunctions.o: In function `boost::system::error_code::error_code()':
builtinFunctions.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
builtinFunctions.o: In function `boost::filesystem3::exists(boost::filesystem3::path const&)':
...
This is a Makefile that I use:
CC=g++
CFLAGS=-std=c++0x -c -Wall -I . -I ./boost_1_48_0/ -DBOOST_THREAD_USE_LIB
all: project
project: builtinFunctions.o main.o operators.o conversionUtils.o
$(CC) -L./boost_1_48_0/stage/lib/ \
-lpthread -lboost_date_time-gcc46-mt-s-1_48 -lboost_program_options-gcc46-mt-s-1_48 \
-lboost_filesystem-gcc46-mt-s-1_48 -lboost_system-gcc46-mt-s-1_48 builtinFunctions.o \
main.o operators.o conversionUtils.o -o project
main.o: main.cpp
$(CC) $(CFLAGS) main.cpp
operators.o: operators.cpp
$(CC) $(CFLAGS) operators.cpp
conversionUtils.o: conversionUtils.cpp
$(CC) $(CFLAGS) conversionUtils.cpp
builtinFunctions.o: builtinFunctions.cpp
$(CC) $(CFLAGS) builtinFunctions.cpp
clean:
rm -rf *o project
Anything else I could try besides an earlier version of GCC? Thank you.
The order of libraries on link line matters, and yours is wrong.
Related
I am programming a module for my Alderbaran Nao V5 robot. Alderbaran recommends using qibuild to compile a module, and I was able to successfully do so, but now I am trying to migrate towards writing my own makefile and using g++.
I am encountering the following error:
/usr/lib/gcc/i686-pc-linux-gnu/4.5.3/../../../../lib/crt1.o: In function
`_start':
(.text+0x18): undefined reference to `main'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqimessaging.so: undefined reference to `std::__detail::_List_node_base::swap(std::__detail::_List_node_base&, std::__detail::_List_node_base&)#GLIBCXX_3.4.15'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqi.so: undefined reference to `std::invalid_argument::~invalid_argument()#GLIBCXX_3.4.15'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqitype.so: undefined reference to `std::out_of_range::~out_of_range()#GLIBCXX_3.4.15'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqitype.so: undefined reference to `std::__detail::_List_node_base::_M_transfer(std::__detail::_List_node_base*, std::__detail::_List_node_base*)#GLIBCXX_3.4.15'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqimessaging.so: undefined reference to `std::__detail::_List_node_base::_M_unhook()#GLIBCXX_3.4.15'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqimessaging.so: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)#GLIBCXX_3.4.15'
/home/nao/naoqi-sdk-2.1.3.3-linux32/lib/libqi.so: undefined reference to `posix_spawnp#GLIBC_2.15'
collect2: ld returned 1 exit status
make: *** [shm.so] Error 1
Here is the makefile I am using:
#Variables
CXXFLAGS=-Wall -g
CXX = g++
NaoQi_INC = /home/nao/naoqi-sdk-2.1.3.3-linux32/include
NaoQi_LIB = -L/home/nao/naoqi-sdk-2.1.3.3-linux32/lib -lalcommon -lalerror -lalproxies -lalvalue -lqimessaging -lqitype -lqi
#Object Targets
main.o: main.cpp shm.h
$(CXX) $(CXXFLAGS) -c -I$(NaoQi_INC) main.cpp
shm.o: shm.cpp shm.h $(NaoQi_INC)/alcommon/alproxy.h $(NaoQi_INC)/alcommon/albroker.h $(NaoQi_INC)/alcommon/almodule.h
$(CXX) $(CXXFLAGS) -c -I$(NaoQi_INC) shm.cpp
#Library Targets
shm.so: main.o shm.o
$(CXX) $(CXXFLAGS) -o shm.so main.o shm.o -L/usr/local/lib -lm $(NaoQi_LIB)
clean:
rm -f *o main
rm -f *o shm
all: shm.o main.o shm.so
I noticed that the gentoo operating system I am compiling on has up to GLIBCXX_3.4.14 but does not have GLIBCXX_3.4.15. How can I fix this issue? Why would this issue not present itself when I build the module using qibuild?
Interestingly, the problem was that my .so linking command was missing a -shared flag. Not sure why that gave all of the errors I ran into, however.
This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 6 years ago.
I have a project with several .cpp and .h files, and I am trying to split the source into core / generic stuff, and application specific code. Based on that, I separated the code files into a Common folder and compiled it as a library. Below is the Makefile for that lib:
CFLAGS=-std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib
SOURCES = $(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
OUTPUTFILE=libcommon.a
all: $(OUTPUTFILE)
$(OUTPUTFILE): $(OBJECTS)
ar rcs $(OUTPUTFILE) $(OBJECTS)
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $# $(GPROF)
clean:
rm -f $(OBJECTS) $(OUTPUTFILE)
Then I created a sample main file just to try out the compilation of an app using that library.
Here is the code of the main source file:
#include "../Common/Functions.h"
#include "../Common/Logger.h"
int main() {
Logger::Init(false, false);
Logger::Debug("Test");
string path = Functions::GetAppPath();
Logger::Debug("App Path: ", path.c_str());
return 0;
}
The functions file that is being referenced uses boost, and here is the makefile for this app that uses the library:
CC=g++
CFLAGS=-Wl,--verbose -std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib
LDFLAGS=-I../boost_1_57_0 -L../boost_1_57_0/stage/lib -L../boost_libs/lib -L/usr/lib64 -L/usr/kerberos/lib -L/usr/lib -L../Common
LIBS=-lz -lkrb5 -lk5crypto -lcom_err -lresolv -lm -lpthread -lrt -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -rdynamic -lcurl -lcommon
SOURCES = $(wildcard *.cpp)
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=testApp
GPROF=-pg
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $# $(LIBS) $(GPROF)
.cpp.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $# $(GPROF)
clean:
rm -rf *o $(OBJECTS)
When I try to compile, I get the following errors, complaining about undefined references to boost:
g++ -Wl,--verbose -std=c++11 -g -c -pedantic -Wall -Wextra -I../boost_1_57_0 -L../boost_1_57_0/stage/lib main.cpp -o main.o -pg
g++ -I../boost_1_57_0 -L../boost_1_57_0/stage/lib -L../boost_libs/lib -L/usr/lib64 -L/usr/kerberos/lib -L/usr/lib -L../Common main.o -o testApp -lz -lkrb5 -lk5crypto -lcom_err -lresolv -lm -lpthread -lrt -lboost_system -lboost_filesystem -lboost_thread -lboost_date_time -rdynamic -lcurl -lcommon -pg
../Common/libcommon.a(Functions.o): In function `Functions::GetAppPath()':
/media/software/Robots/Common/Functions.cpp:43: undefined reference to `boost::filesystem::path::parent_path() const'
../Common/libcommon.a(Functions.o): In function `boost::filesystem::initial_path()':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:583: undefined reference to `boost::filesystem::detail::initial_path(boost::system::error_code*)'
../Common/libcommon.a(Functions.o): In function `boost::filesystem::system_complete(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:655: undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Functions.o): In function `unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::string const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/date_time/date_parsing.hpp:67: undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'
../Common/libcommon.a(Logger.o): In function `Logger::Cleanup()':
/media/software/Robots/Common/Logger.cpp:84: undefined reference to `boost::thread::interrupt()'
../Common/libcommon.a(Logger.o): In function `Logger::InitFile(std::string, bool, std::_Ios_Openmode)':
/media/software/Robots/Common/Logger.cpp:186: undefined reference to `boost::filesystem::path::parent_path() const'
/media/software/Robots/Common/Logger.cpp:187: undefined reference to `boost::filesystem::path::parent_path() const'
../Common/libcommon.a(Logger.o): In function `Logger::Process()':
/media/software/Robots/Common/Logger.cpp:241: undefined reference to `boost::this_thread::interruption_point()'
../Common/libcommon.a(Logger.o): In function `boost::detail::thread_data_base::thread_data_base()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/pthread/thread_data.hpp:143: undefined reference to `vtable for boost::detail::thread_data_base'
../Common/libcommon.a(Logger.o): In function `boost::thread::start_thread()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:179: undefined reference to `boost::thread::start_thread_noexcept()'
../Common/libcommon.a(Logger.o): In function `boost::thread::~thread()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:254: undefined reference to `boost::thread::detach()'
../Common/libcommon.a(Logger.o): In function `boost::thread::get_id() const':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:741: undefined reference to `boost::thread::native_handle()'
../Common/libcommon.a(Logger.o): In function `boost::thread::join()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:767: undefined reference to `boost::thread::join_noexcept()'
../Common/libcommon.a(Logger.o): In function `boost::filesystem::exists(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:404: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Logger.o): In function `boost::filesystem::create_directories(boost::filesystem::path const&)':
/media/software/Robots/Common/../boost_1_57_0/boost/filesystem/operations.hpp:523: undefined reference to `boost::filesystem::detail::create_directories(boost::filesystem::path const&, boost::system::error_code*)'
../Common/libcommon.a(Logger.o): In function `boost::detail::thread_data<void (*)()>::~thread_data()':
/media/software/Robots/Common/../boost_1_57_0/boost/thread/detail/thread.hpp:90: undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
../Common/libcommon.a(Logger.o):(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[_ZTIN5boost6detail11thread_dataIPFvvEEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: error: ld returned 1 exit status
Needless to say that the project as a whole compiles with no issue.
This is my first attempt at building a c++ linux library and using it in another application, so I might be doing a rookie mistake, so bear that in mind.
Help is very much appreciated.
Thank you.
The order of libraries on the command line is significant to the linker. It processes libraries from left to right, resolving as-yet unresolved references already known to it against any functions provided by the current library.
Moreover, and particularly relevant here, if a given library contains references to functions that it does not itself provide then the linker does not resolve those against libraries it has already processed. That's why you have unresolved references: you have -lcommon last among your libraries, so function references therein will be resolved against only the C standard library.
It is valid to list libraries more than once in the link command, and sometimes that is needed, but in this case I think it makes sense simply to put -lcommon as the first library instead of the last. That will resolve the issue. You can even conceptualize this as putting the library most closely related to the main program closest to it in the link command.
I want to link my project to a static library (msodbcsql11.lib), and I want to include it's header (msodbcsql.h) and another header file of a framework otlv4.h) using a simple makefile, but it looks like it can't find the library. Here is my makefile:
CC=g++
LDFLAGS=
CFLAGS=-c -Wall
SOURCES=main.cpp
LIBB = C:\temp\lib
LIBINCL = C:\temp\include
CFLAGS += -I$(LIBINCL)
LDFLAGS += -L$(LIBB)
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=main
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
And here is my c++ code:
#include <iostream>
#define OTL_ODBC_MSSQL_2008 // Compile OTL 4/ODBC, MS SQL 2008
#include <otlv4.h>
int main(){
otl_connect db; //undefined reference errors
}
Here is the build when I declared otl_connect:
18:42:33 **** Incremental Build of configuration Default for project mak ****
make all
g++ -c -Wall -IC:\temp\include main.cpp -o main.o
g++ -LC:\temp\lib main.o -o main
main.o:main.cpp:(.text$_ZN8otl_connD1Ev[_ZN8otl_connD1Ev]+0x66): undefined reference to `SQLFreeHandle'
main.o:main.cpp:(.text$_ZN8otl_connD1Ev[_ZN8otl_connD1Ev]+0x66): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SQLFreeHandle'
main.o:main.cpp:(.text$_ZN8otl_connD1Ev[_ZN8otl_connD1Ev]+0x9e): undefined reference to `SQLFreeHandle'
main.o:main.cpp:(.text$_ZN8otl_connD1Ev[_ZN8otl_connD1Ev]+0x9e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SQLFreeHandle'
main.o:main.cpp:(.text$_ZN8otl_conn6logoffEv[_ZN8otl_conn6logoffEv]+0x54): undefined reference to `SQLDisconnect'
main.o:main.cpp:(.text$_ZN8otl_conn6logoffEv[_ZN8otl_conn6logoffEv]+0x54): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SQLDisconnect'
main.o:main.cpp:(.text$_ZN8otl_conn5errorER7otl_exc[_ZN8otl_conn5errorER7otl_exc]+0x70): undefined reference to `SQLGetDiagRec'
main.o:main.cpp:(.text$_ZN8otl_conn5errorER7otl_exc[_ZN8otl_conn5errorER7otl_exc]+0x70): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SQLGetDiagRec'
main.o:main.cpp:(.text$_ZN8otl_conn6commitEv[_ZN8otl_conn6commitEv]+0x23): undefined reference to `SQLEndTran'
main.o:main.cpp:(.text$_ZN8otl_conn6commitEv[_ZN8otl_conn6commitEv]+0x23): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SQLEndTran'
collect2: error: ld returned 1 exit status
makefile:14: recipe for target 'main' failed
make: *** [main] Error 1
18:42:35 Build Finished (took 1s.993ms)
What is wrong with my makefile? What should I do?
edit: I updated based on #Jonathan Wakely's answer:
LIBB = C:\temp\lib
LIBFILE = msodbcsql11
LDFLAGS += -L$(LIBB) -l$(LIBFILE)
I'm still getting the same errors
Update: Updated makefile as suggested by #Jonathan Wakely, but still getting errors. BTW, I changed the file format of libmsodbcsql11.lib to libmsodbcsql11.a because the compiler can't detect the .lib version
CC=g++
LDFLAGS=
CFLAGS=-c -Wall
SOURCES=main.cpp
LIBB = C:\temp\lib
LIBFILE = msodbcsql11
LIBINCL = C:\temp\include
CFLAGS += -I$(LIBINCL)
OBJECTS=$(SOURCES:.cpp=.o)
LDFLAGS += -L$(LIBB) -l$(LIBFILE)
EXECUTABLE=main
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) -o $#
.cpp.o:
$(CC) $(CFLAGS) $< -o $#
The -L flag only tells the linker where to look for libraries, you need to use -l to tell it which library to link to.
This might be helpful...
Apparently the OTL library requires the odbc32.lib file to call ODBC functions. It's a little confusing because the microsoft ODBC driver have this msodbcsql11.lib, apparently it is not what's needed. Regardless the previous versions of my makefile did not call any library, so I accepted #Jonathan Wakely's answer.
I'm trying to compile a piece of code that creates a TNonblockingServer and I get the following compile error. Any idea what's wrong?
something_server.cpp:(.text+0x1ad): undefined reference to `apache::thrift::server::TNonblockingServer::serve()'
something_server.cpp:(.text+0x1c1): undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()'
something_server.cpp:(.text+0x280): undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()'
I performed the steps outlined here while installing thrift.
http://thrift.apache.org/docs/install/os_x/
Here's my makefile
GEN_SRC := Something.cpp something_constants.cpp something_types.cpp
GEN_OBJ := $(patsubst %.cpp,%.o, $(GEN_SRC))
THRIFT_DIR := /usr/local/include/thrift
BOOST_DIR := /usr/local/include
INC := -I$(THRIFT_DIR) -I$(BOOST_DIR)
.PHONY: all clean
all: something_server something_client
%.o: %.cpp
$(CXX) -Wall -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H $(INC) -c $< -o $#
something_server: something_server.o $(GEN_OBJ)
$(CXX) $^ -o $# -L/usr/local/lib -lthrift
something_client: something_client.o $(GEN_OBJ)
$(CXX) $^ -o $# -L/usr/local/lib -lthrift
clean:
$(RM) *.o something_server something_client
As pointed out by Dmitry, if we add -lthriftnb to compiling command, it solves the problem. These missing references are found in libthriftnb.so This file has references to libevent. So I had to include -levent to compiling command. Without -levent linker generates multiple error messages. Some of the messages are as follows -
/usr/local/lib/libthriftnb.so: undefined reference to `event_set'
/usr/local/lib/libthriftnb.so: undefined reference to `evbuffer_new'
/usr/local/lib/libthriftnb.so: undefined reference to `evhttp_free'
.
.
.
.
/usr/local/lib/libthriftnb.so: undefined reference to `event_del'
I'm current working on a C++ that I edit locally on my Mac but run on an Ubuntu server. I always make sure that the code compiles on my mac before uploading it to the server to compile it there, where I have to use a makefile to link with libraries that are installed in my local directory. Basically, I had edited a significant portion of my code, found that it compiled on my mac, and uploaded it to the server to compile, but it doesn't compile! Luckily, I had a backup version of the code, so I tried that on the server, and that won't compile anymore either! In between the last time I knew that my code compiled on the server and now, I know that they ran some updates, but that's all I can think of that's different. For reference, here's my make file:
LOCAL_INCLUDE = /home/schraiber/.local/include
LOCAL_LIB = /home/schraiber/.local/lib
CXXFLAGS = -I$(LOCAL_INCLUDE)
CXX_LDFLAGS = -L$(LOCAL_LIB) -lgsl -lm -lgslcblas -lpthread
CoalHMMgf: main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o ThreadData.h
g++ $(CXXFLAGS) $(CXX_LDFLAGS) main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o -o CoalHMMgf
main.o: main.cpp IOUtilities.h parameters.h Algorithms.h Optimization.h probabilities.h ThreadData.h Data.h
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c main.cpp
IOutilities.o: IOUtilities.h IOUtilities.cpp parameters.h data.h
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c IOUtilities.cpp
parameters.o: parameters.h parameters.cpp
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c parameters.cpp
Algorithms.o: Algorithms.h Algorithms.cpp
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c Algorithms.cpp
Optimization.o: Optimization.h Optimization.cpp Algorithms.h parameters.h probabilities.h RNGUtilities.h ThreadData.h IOUtilities.h
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c Optimization.cpp
probabilities.o: probabilities.h probabilities.cpp parameters.h
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c probabilities.cpp
RNGUtilities.o: RNGUtilities.h RNGUtilities.cpp
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c RNGUtilities.cpp
Data.o: Data.h Data.cpp
g++ $(CXXFLAGS) $(CXX_LDFLAGS) -c Data.cpp
and the error:
g++ -I/home/schraiber/.local/include -L/home/schraiber/.local/lib -lgsl -lm -lgslcblas -lpthread main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o -o CoalHMMgf
main.o: In function `main':
main.cpp:(.text+0xbf1): undefined reference to `pthread_create'
main.cpp:(.text+0xd0e): undefined reference to `pthread_join'
Optimization.o: In function `my_df(gsl_vector const*, void*, gsl_vector*)':
Optimization.cpp:(.text+0x3149): undefined reference to `gsl_vector_alloc'
Optimization.cpp:(.text+0x316b): undefined reference to `gsl_vector_get'
Optimization.cpp:(.text+0x3180): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x31bc): undefined reference to `gsl_vector_get'
Optimization.cpp:(.text+0x31ec): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x323b): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x327e): undefined reference to `gsl_vector_set'
Optimization.cpp:(.text+0x32c9): undefined reference to `gsl_vector_set'
Optimization.o: In function `MHthreaded(void*)':
Optimization.cpp:(.text+0x3489): undefined reference to `gsl_rng_env_setup'
Optimization.cpp:(.text+0x3490): undefined reference to `gsl_rng_default'
Optimization.cpp:(.text+0x360b): undefined reference to `gsl_rng_uniform'
Optimization.cpp:(.text+0x3653): undefined reference to `gsl_ran_gaussian'
Optimization.cpp:(.text+0x3686): undefined reference to `gsl_ran_gaussian'
Optimization.cpp:(.text+0x377f): undefined reference to `gsl_rng_uniform'
RNGUtilities.o: In function `AllocRNG(gsl_rng*&, gsl_rng_type const*, int)':
RNGUtilities.cpp:(.text+0x9a): undefined reference to `gsl_rng_alloc'
RNGUtilities.cpp:(.text+0xba): undefined reference to `gsl_rng_set'
RNGUtilities.o: In function `FreeRNG(gsl_rng*&)':
RNGUtilities.cpp:(.text+0xe3): undefined reference to `gsl_rng_free'
collect2: ld returned 1 exit status
make: *** [CoalHMMgf] Error 1
and just to verify that gsl is installed in the local directory:
schraiber#trump:~/test_rsync$ ls ~/.local/lib
libbpp-core.a libbpp-core.so.2.0.0 libbpp-seq.so.9 libgslcblas.a libgslcblas.so.0 libgsl.so pkgconfig
libbpp-core.so libbpp-seq.a libbpp-seq.so.9.1.0 libgslcblas.la libgslcblas.so.0.0.0 libgsl.so.0 python2.7
libbpp-core.so.2 libbpp-seq.so libgsl.a libgslcblas.so libgsl.la libgsl.so.0.16.0
schraiber#trump:~/test_rsync$ ls ~/.local/include/
Bpp gsl
An interesting thing to note is that my program is also supposed to link with Bpp, and it does that just fine as far as I can tell.
Your "-lfoo" parameters should come last on your "g++" command line. So, for example, make this change in your makefile:
CoalHMMgf: main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o ThreadData.h
g++ $(CXXFLAGS) main.o IOUtilities.o parameters.o Algorithms.o Optimization.o probabilities.o RNGUtilities.o Data.o -o CoalHMMgf $(CXX_LDFLAGS)
Libraries have to be defined on the link line such that the library containing no other references is the very last one. Libraries that depend on code from a second library need to be listed first. They must be listed after the .o files, or else the .o files are assumed to be self-contained and don't need the libraries.