I have small program using htmlcxx but when I try building the code it gives linker error.
I just downloaded the htmlcxx.084.zip, unzipped it and placed it in Dev-Cpp\include\c++\3.4.2\htmlcxx. The code does not give any build error but the linking fails.
[Linker error] undefined reference to `htmlcxx::HTML::ParserDom::parseTree(std::string const&)'
[Linker error] undefined reference to `htmlcxx::HTML::operator<<(std::ostream&, tree<htmlcxx::HTML::Node, std::allocator<tree_node_<htmlcxx::HTML::Node> > > const&)'
[Linker error] undefined reference to `htmlcxx::HTML::Node::parseAttributes()'
[Linker error] undefined reference to `vtable for htmlcxx::HTML::ParserDom'
ld returned 1 exit status
[Build Error] [test.exe] Error 1
Am I missing something in the Makefile or the something is missing in the lib path.?
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = tree_test.o $(RES)
LINKOBJ = tree_test.o $(RES)
LIBS = -L"C:/Dev-Cpp/lib" -lwinmm -lgdi32
INCS = -I"C:/Dev-Cpp/include"
CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"
BIN = test.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "test.exe" $(LIBS)
Related
I just implemented the distributed version of a database project using gRPC. When I tried to make with my makefile, I keep getting the undefined reference errors with protobuf and gRPC. Parts of the outputs of make is below. I only included a portion of it because of the word limits.
g++ -o rundb benchmarks/ycsb_query.o benchmarks/tpcc_wl.o benchmarks/ycsb_wl.o benchmarks/ycsb_store_procedure.o benchmarks/tpcc_query.o benchmarks/tpcc_helper.o benchmarks/tpcc_store_procedure.o concurrency_control/lock_manager.o concurrency_control/tictoc_manager.o concurrency_control/row_f1.o concurrency_control/row_lock.o concurrency_control/f1_manager.o concurrency_control/row_tictoc.o storage/catalog.o storage/index_hash.o storage/index_btree.o storage/index_base.o storage/row.o storage/log.o storage/table.o system/stats.o system/manager.o system/cc_manager.o system/thread.o system/global.o system/logging_thread.o system/store_procedure.o system/txn.o system/worker_thread.o system/parser.o system/workload.o system/txn_table.o system/main.o system/caching.o utils/helper.o utils/semaphore_sync.o utils/packetize.o grpc/grpc_async_client.o grpc/grpc_sync_server.o grpc/grpc_async_server.o grpc/grpc_sync_client.o -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf -Wall -g -std=c++11 -I. -I./benchmarks -I./concurrency_control -I./storage -I./system -I./transport -I./utils -I./grpc -I./grpc_system -D NOGRAPHITE=1 -O3 -g -ggdb
/usr/bin/ld: concurrency_control/lock_manager.o: in function `google::protobuf::internal::GenericTypeHandler<sundial_rpc::SundialRequest_TupleData>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:802: undefined reference to `sundial_rpc::SundialRequest_TupleData* google::protobuf::Arena::CreateMaybeMessage<sundial_rpc::SundialRequest_TupleData>(google::protobuf::Arena*)'
/usr/bin/ld: system/stats.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const& sundial_rpc::SundialRequest_RequestType_Name<unsigned int>(unsigned int)':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:105: undefined reference to `sundial_rpc::SundialRequest_RequestType_descriptor()'
/usr/bin/ld: system/stats.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const& sundial_rpc::SundialResponse_ResponseType_Name<unsigned int>(unsigned int)':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:136: undefined reference to `sundial_rpc::SundialResponse_ResponseType_descriptor()'
/usr/bin/ld: system/txn.o: in function `google::protobuf::internal::GenericTypeHandler<sundial_rpc::SundialResponse_TupleData>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:802: undefined reference to `sundial_rpc::SundialResponse_TupleData* google::protobuf::Arena::CreateMaybeMessage<sundial_rpc::SundialResponse_TupleData>(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `TxnManager::RemoteNodeInfo::~RemoteNodeInfo()':
/home/libin/Sundial/system/txn.h:102: undefined reference to `sundial_rpc::SundialResponse::~SundialResponse()'
/usr/bin/ld: /home/libin/Sundial/system/txn.h:102: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: system/txn.o: in function `sundial_rpc::SundialRequest::SundialRequest()':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:494: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `sundial_rpc::SundialResponse::SundialResponse()':
/home/libin/Sundial/./grpc_system/sundial_grpc.pb.h:909: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `TxnManager::send_remote_read_request(unsigned long, unsigned long, unsigned long, unsigned long, access_t)':
/home/libin/Sundial/system/txn.cpp:301: undefined reference to `sundial_rpc::SundialRequest::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:302: undefined reference to `sundial_rpc::SundialResponse::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(sundial_rpc::SundialResponse const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(sundial_rpc::SundialRequest const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:309: undefined reference to `sundial_rpc::SundialResponse::~SundialResponse()'
/usr/bin/ld: system/txn.o: in function `google::protobuf::internal::GenericTypeHandler<sundial_rpc::SundialRequest_ReadRequest>::New(google::protobuf::Arena*)':
/usr/local/include/google/protobuf/repeated_field.h:802: undefined reference to `sundial_rpc::SundialRequest_ReadRequest* google::protobuf::Arena::CreateMaybeMessage<sundial_rpc::SundialRequest_ReadRequest>(google::protobuf::Arena*)'
/usr/bin/ld: system/txn.o: in function `TxnManager::process_2pc_phase1()':
/home/libin/Sundial/system/txn.cpp:351: undefined reference to `sundial_rpc::SundialRequest::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:352: undefined reference to `sundial_rpc::SundialResponse::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(sundial_rpc::SundialResponse const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(sundial_rpc::SundialRequest const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:362: undefined reference to `sundial_rpc::SundialResponse::~SundialResponse()'
/usr/bin/ld: system/txn.o: in function `TxnManager::process_2pc_phase2(RC)':
/home/libin/Sundial/system/txn.cpp:420: undefined reference to `sundial_rpc::SundialRequest::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:421: undefined reference to `sundial_rpc::SundialResponse::Clear()'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:429: undefined reference to `sundial_rpc::SundialResponse::SundialResponse(sundial_rpc::SundialResponse const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:429: undefined reference to `sundial_rpc::SundialRequest::SundialRequest(sundial_rpc::SundialRequest const&)'
/usr/bin/ld: /home/libin/Sundial/system/txn.cpp:429: undefined reference to `sundial_rpc::SundialRequest::~SundialRequest()'
/usr/bin/ld: /home/libin/Sundial/grpc/grpc_sync_client.cpp:37: undefined reference to `sundial_rpc::Sundial_GRPC_SYNC::Stub::contactRemote(grpc_impl::ClientContext*, sundial_rpc::SundialRequest const&, sundial_rpc::SundialResponse*)'
/usr/bin/ld: /home/libin/Sundial/grpc/grpc_sync_client.cpp:36: undefined reference to `grpc_impl::ClientContext::~ClientContext()'
/usr/bin/ld: grpc/grpc_sync_client.o: in function `sundial_rpc::Sundial_GRPC_SYNC::Stub::~Stub()':
/home/libin/Sundial/./grpc_system/sundial_grpc.grpc.pb.h:73: undefined reference to `vtable for sundial_rpc::Sundial_GRPC_SYNC::Stub'
/usr/bin/ld: grpc/grpc_sync_client.o: in function `sundial_rpc::Sundial_GRPC_SYNC::Stub::~Stub()':
/home/libin/Sundial/./grpc_system/sundial_grpc.grpc.pb.h:73: undefined reference to `vtable for sundial_rpc::Sundial_GRPC_SYNC::Stub'
/usr/bin/ld: grpc/grpc_sync_client.o: in function `Sundial_Sync_Client::contactRemote(unsigned long, sundial_rpc::SundialRequest, sundial_rpc::SundialResponse)':
/home/libin/Sundial/grpc/grpc_sync_client.cpp:36: undefined reference to `grpc_impl::ClientContext::~ClientContext()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:20: rundb] Error 1
I did read some other previous posts suggesting it is caused by not linking the protobuf library but I did include it in LDFLAGS. The makefile is below.
CC=g++
CFLAGS=-Wall -g -std=c++11
.SUFFIXES: .o .cpp .h
SRC_DIRS = ./ ./benchmarks/ ./concurrency_control/ ./storage/ ./system/ ./transport/ ./utils/ ./grpc/ ./grpc_system/
INCLUDE = -I. -I./benchmarks -I./concurrency_control -I./storage -I./system -I./transport -I./utils -I./grpc -I./grpc_system
CFLAGS += $(INCLUDE) -D NOGRAPHITE=1 -O3 -g -ggdb
LDFLAGS = -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf
LDFLAGS += $(CFLAGS)
CPPS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)*.cpp))
OBJS = $(CPPS:.cpp=.o)
DEPS = $(CPPS:.cpp=.d)
all:rundb
rundb : $(OBJS)
$(CC) -o $# $^ $(LDFLAGS)
-include $(OBJS:%.o=%.d)
%.d: %.cpp
$(CC) -MM -MT $*.o -MF $# $(CFLAGS) $<
%.o: %.cpp %.d
$(CC) -c $(CFLAGS) -o $# $<
.PHONY: clean
clean:
rm -f rundb *.o */*.o *.d */*.d
So I thought LDFLAGS = -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf would resolve this but it did not.
You can try following these two steps:
Step 1:
Add the below two lines in your makefile:
CFLAGS += `pkg-config --cflags protobuf grpc`
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
-lgrpc++_reflection\
-ldl
Please refer this Makefile (C++ grpc example for load balancing): https://chromium.googlesource.com/external/github.com/grpc/grpc/+/HEAD/examples/cpp/load_balancing/Makefile
Your Makefile should look like this:
CC=g++
CFLAGS=-Wall -g -std=c++11
# Add the below line
CFLAGS += `pkg-config --cflags protobuf grpc`
.SUFFIXES: .o .cpp .h
SRC_DIRS = ./ ./benchmarks/ ./concurrency_control/ ./storage/ ./system/ ./transport/ ./utils/ ./grpc/ ./grpc_system/
INCLUDE = -I. -I./benchmarks -I./concurrency_control -I./storage -I./system -I./transport -I./utils -I./grpc -I./grpc_system
CFLAGS += $(INCLUDE) -D NOGRAPHITE=1 -O3 -g -ggdb
LDFLAGS = -Wall -L./libs -pthread -lrt -std=c++0x -O3 -ljemalloc -lprotobuf
LDFLAGS += $(CFLAGS)
# Add the below line
LDFLAGS += -L/usr/local/lib `pkg-config --libs protobuf grpc++ grpc`\
-lgrpc++_reflection\
-ldl
CPPS = $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)*.cpp))
OBJS = $(CPPS:.cpp=.o)
DEPS = $(CPPS:.cpp=.d)
all:rundb
rundb : $(OBJS)
$(CC) -o $# $^ $(LDFLAGS)
-include $(OBJS:%.o=%.d)
%.d: %.cpp
$(CC) -MM -MT $*.o -MF $# $(CFLAGS) $<
%.o: %.cpp %.d
$(CC) -c $(CFLAGS) -o $# $<
.PHONY: clean
clean:
rm -f rundb *.o */*.o *.d */*.d
Step 2:
In your command prompt, you need to find the path of two files:
Path of "protobuf.pc"
Path of "grpc.pc"
You can find the path using these commands:
sudo find / -name "protobuf.pc"
Example output: /usr/local/lib/pkgconfig
sudo find / -name "grpc.pc"
Example output: /usr/lib/pkgconfig"
At last, you need to add these two paths separated by colon (:) in the environment variable "PKG_CONFIG_PATH" by running this command:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/lib/pkgconfig"
Now, you can run your commands and proceed further.
NOTE:
In step 2, if both protobuf.pc and grpc.pc are present in the same directory,
then you need to specify only that directory in the environment variable.
Example:
sudo find / -name "protobuf.pc"
Example output: /lib64/pkgconfig
sudo find / -name "grpc.pc"
Example output: /lib64/pkgconfig
In this case, you can set environment variable as:
export PKG_CONFIG_PATH="/lib64/pkgconfig"
Actually, I am working with the well-known SVM-struct project (http://www.cs.cornell.edu/people/tj/svm_light/svm_struct.html)on Ubuntu 16.04. I followed the instructions in http://www.cs.cornell.edu/people/tj/svm_light/svm_multiclass.html to use SVM-multiclass, downloaded the source code and make. But I met some errors when building the project:
$ make
cd svm_light; make svm_learn_hideo_noexe
make[1]: Entering directory '/home/parallels/CLionProjects/svm_multiclass/svm_light'
make[1]: Nothing to be done for 'svm_learn_hideo_noexe'.
make[1]: Leaving directory '/home/parallels/CLionProjects/svm_multiclass/svm_light'
cd svm_struct; make svm_struct_noexe
make[1]: Entering directory '/home/parallels/CLionProjects/svm_multiclass/svm_struct'
make[1]: Nothing to be done for 'svm_struct_noexe'.
make[1]: Leaving directory '/home/parallels/CLionProjects/svm_multiclass/svm_struct'
gcc -O3 -lm -Wall svm_struct/svm_struct_learn.o svm_struct_learn_custom.o svm_struct_api.o svm_light/svm_hideo.o svm_light/svm_learn.o svm_light/svm_common.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o -o svm_multiclass_learn
svm_light/svm_learn.o: In function `estimate_sphere':
svm_learn.c:(.text+0x6e88): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `estimate_r_delta':
svm_learn.c:(.text+0x7053): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `estimate_r_delta_average':
svm_learn.c:(.text+0x7b04): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `length_of_longest_document_vector':
svm_learn.c:(.text+0x7b86): undefined reference to `sqrt'
svm_light/svm_learn.o: In function `incorporate_unlabeled_examples':
svm_learn.c:(.text+0x89eb): undefined reference to `sqrt'
svm_light/svm_learn.o:svm_learn.c:(.text+0xc952): more undefined references to `sqrt' follow
svm_light/svm_common.o: In function `classify_example':
svm_common.c:(.text+0x38f): undefined reference to `tanh'
svm_common.c:(.text+0x42d): undefined reference to `exp'
svm_common.c:(.text+0x4a7): undefined reference to `pow'
svm_light/svm_common.o: In function `kernel':
svm_common.c:(.text+0x870): undefined reference to `tanh'
svm_common.c:(.text+0x90d): undefined reference to `exp'
svm_common.c:(.text+0x988): undefined reference to `pow'
svm_light/svm_common.o: In function `model_length_s':
svm_common.c:(.text+0x2c8d): undefined reference to `sqrt'
svm_light/svm_common.o: In function `model_length_n':
svm_common.c:(.text+0x2f5c): undefined reference to `sqrt'
svm_light/svm_common.o: In function `cholesky_matrix':
svm_common.c:(.text+0x3c6f): undefined reference to `sqrt'
svm_light/svm_common.o: In function `find_indep_subset_of_matrix':
svm_common.c:(.text+0x3f41): undefined reference to `sqrt'
svm_light/svm_common.o: In function `single_kernel':
svm_common.c:(.text+0xc0c): undefined reference to `tanh'
svm_common.c:(.text+0xc84): undefined reference to `pow'
svm_common.c:(.text+0xcfb): undefined reference to `exp'
collect2: error: ld returned 1 exit status
Makefile:48: recipe for target 'svm_multiclass_learn' failed
make: *** [svm_multiclass_learn] Error 1
I think the Makefile has already included -lm.
# Makefile for SVM-multiclass, 03.07.04
#Use the following to compile under unix or cygwin
CC = gcc
LD = gcc
#Call 'make' using the following line to make CYGWIN produce stand-alone Windows executables
# make 'SFLAGS=-mno-cygwin'
CFLAGS = $(SFLAGS) -O3 -fomit-frame-pointer -ffast-math -Wall
LDFLAGS = $(SFLAGS) -O3 -lm -Wall
#CFLAGS = $(SFLAGS) -pg -Wall
#LDFLAGS = $(SFLAGS) -pg -lm -Wall
all: svm_multiclass_learn svm_multiclass_classify
.PHONY: clean
clean: svm_light_clean svm_struct_clean
rm -f *.o *.tcov *.d core gmon.out *.stackdump
#-----------------------#
#---- SVM-light ----#
#-----------------------#
svm_light_hideo_noexe:
cd svm_light; make svm_learn_hideo_noexe
svm_light_clean:
cd svm_light; make clean
#----------------------#
#---- STRUCT SVM ----#
#----------------------#
svm_struct_noexe:
cd svm_struct; make svm_struct_noexe
svm_struct_clean:
cd svm_struct; make clean
#-------------------------#
#---- SVM MULTICLASS ----#
#-------------------------#
svm_multiclass_classify: svm_light_hideo_noexe svm_struct_noexe svm_struct_api.o svm_struct/svm_struct_classify.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o
$(LD) $(LDFLAGS) svm_struct_api.o svm_struct/svm_struct_classify.o svm_light/svm_common.o svm_struct/svm_struct_common.o -o svm_multiclass_classify $(LIBS)
svm_multiclass_learn: svm_light_hideo_noexe svm_struct_noexe svm_struct_api.o svm_struct_learn_custom.o svm_struct/svm_struct_learn.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o
$(LD) $(LDFLAGS) svm_struct/svm_struct_learn.o svm_struct_learn_custom.o svm_struct_api.o svm_light/svm_hideo.o svm_light/svm_learn.o svm_light/svm_common.o svm_struct/svm_struct_common.o svm_struct/svm_struct_main.o -o svm_multiclass_learn $(LIBS)
svm_struct_api.o: svm_struct_api.c svm_struct_api.h svm_struct_api_types.h svm_struct/svm_struct_common.h
$(CC) -c $(CFLAGS) svm_struct_api.c -o svm_struct_api.o
svm_struct_learn_custom.o: svm_struct_learn_custom.c svm_struct_api.h svm_light/svm_common.h svm_struct_api_types.h svm_struct/svm_struct_common.h
$(CC) -c $(CFLAGS) svm_struct_learn_custom.c -o svm_struct_learn_custom.o
The linker collects dependencies first (svm_light/svm_learn.o) and fills them in when it sees a definition (-lm).
You seem to already have a $(LIBS) at the end of your ld invocation, so just:
LIBS += -lm
should fix it.
Other tips:
you can replace the pattern cd X; make TARGET with make -C X TARGET
you can refer to the target as $# and the first prerequisite in the dependency list as $<, so your last rule can be written as:
svm_struct_learn_custom.o: svm_struct_learn_custom.c svm_struct_api.h svm_light/svm_common.h svm_struct_api_types.h svm_struct/svm_struct_common.h
$(CC) -c $(CFLAGS) $< -o $#
where the recipe redefinition of the built-in recipe for compiling .c files, so it suffices to simply list the headers as (extra) prerequisites:
svm_struct_learn_custom.o: svm_struct_api.h svm_light/svm_common.h svm_struct_api_types.h svm_struct/svm_struct_common.h
(Hello, this is my first post, and I am using Dev C++ IDE 5.11)
I included the header, SOIL.h and the linker: -lSOIL.
This program compiles with no problem and runs correctly, but when I add any function into my code from the SOIL library, I receive a linker error.
'recipe for target 'Project1.exe' failed'
Here is the code from SOIL that causes the linker error:
unsigned char* image = SOIL_load_image("container.jpg", &width, &height, 0, SOIL_LOAD_RGB);
(There is probably an easy explanation and answer for this, but I have searched everywhere as I cannot find it.)
Note: I am following a tutorial from the website learnopengl
Here is my makefile.win:
# Project: Project1
# Makefile created by Dev-C++ 5.11
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = Untitled2.o
LINKOBJ = Untitled2.o
LIBS = -L"D:/Dev-Cpp/MinGW32/lib" -L"D:/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lopengl32 -lopengl32 -lmingw32 -lSOIL
INCS = -I"D:/Dev-Cpp/MinGW32/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include"
CXXINCS = -I"D:/Dev-Cpp/MinGW32/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include/c++"
BIN = Project1.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm.exe -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
Untitled2.o: Untitled2.cpp
$(CPP) -c Untitled2.cpp -o Untitled2.o $(CXXFLAGS)
Compilation log:
Compiling project changes...
--------
- Project Filename: D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Project1.dev
- Compiler Name: MinGW GCC 4.7.2 32-bit Release
Building makefile...
--------
- Filename: D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win
Processing makefile...
--------
- Makefile Processor: D:\Dev-Cpp\MinGW32\bin\mingw32-make.exe
- Command: mingw32-make.exe -f "D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win" all
g++.exe Untitled2.o -o Project1.exe -L"D:/Dev-Cpp/MinGW32/lib" -L"D:/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lopengl32 -lmingw32 -Bstatic -lSOIL
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x3e): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x72): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xbe): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xf2): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x115): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x15e): more undefined references to `glGetString#4' follow
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1d1): undefined reference to `wglGetProcAddress#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x5e2): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x66a): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x84f): undefined reference to `glDeleteTextures#8'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xdf8): undefined reference to `glReadPixels#28'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x100d): undefined reference to `glGetIntegerv#8'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1427): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x15a8): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x161a): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x188c): undefined reference to `glTexImage2D#36'
d:/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o): bad reloc address 0x0 in section `.data'
d:/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win:25: recipe for target 'Project1.exe' failed
mingw32-make.exe: *** [Project1.exe] Error 1
Compilation results...
--------
- Errors: 1
- Warnings: 0
- Compilation Time: 0.25s
Thank you so much Patrick Stewart for helping me figure this out.
Oddly enough, when I didn't have the -Bstatic, there was the only one error. When I followed what you said about the compilation log, it gave more errors that I did not know were there. I Googled it and found out an answer from this site: http://www.gamedev.net/topic/614336-soil-linker-errors/
that the -lSOIL had to be before the -lopengl32.
This is weird in my opinion, but it is a solution.
I have been scratching my head since yesterday trying to make gtest work but I just can't fix it after reading the links below.
undefined reference to `pthread_key_create' (linker error)
error during making GTest
The compilation error displayed is this:
g++ main.o tests.o var.o -L ../gmock/lib/.libs -L ../gmock/gtest/lib/.libs
-lgtest -lgmock -lpthread -o test
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_key_create'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_getspecific'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_key_delete'
../gmock/gtest/lib/.libs/libgtest.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
My Makefile is:
CXXFLAGS=-I ../gmock/include -I ../gmock/gtest/include
test:main.o tests.o var.o
g++ $^ -L ../gmock/lib/.libs -L ../gmock/gtest/lib/.libs -lgtest -lgmock -lpthread -o $#
I am still in the process of learning Linux, compiling and linking source files.
The Error is about linking error on pthread.
You have to make the pthread flag to -pthread and the follow CXX should do the trick.
LDLIBS = -L../gmock/lib/.libs -L../gmock/gtest/lib/.libs -lgtest -lgmock
test:main.o tests.o var.o
g++ -isystem $(LDLIBS) -pthread $^ -o $#
This link have a good Makefile which addresses all your problems and it follows general standards on creating a Makefile
I'm a noob to MakeFile. I have read all similar posts on stackoverflow. But still don't know how to do (I'm sure this is a MakeFile problem because I can run it with XCode). Here are my MakeFile and Error msg:
####### Detect system architecture
SYSARCH = i386
ifeq ($(shell uname -m),x86_64)
SYSARCH = x86_64
endif
####### Compiler, tools and options
CXX = g++
LINK = g++
MAKE = make
DELETEFILE = rm -f
DELETEDIR = rm -Rf
DEFINES = -DQT_WEBKIT -DGL_GLEXT_PROTOTYPES
COMMONFLAGS = -Wall -Wextra -pipe -msse2 -Wno-reorder
#-Werror
####### Detect debug or release
DEBUG ?= 0
CXXFLAGS ?=
ifeq ($(DEBUG), 1)
CXXFLAGS += $(COMMONFLAGS) -DDEBUG -DOVR_BUILD_DEBUG -g $(DEFINES)
RELEASETYPE ?= Debug
LFLAGS =
else
CXXFLAGS += $(COMMONFLAGS) -O2 $(DEFINES)
RELEASETYPE ?= Release
LFLAGS = -O1 # Why O1?
endif
####### Paths
OCULUSWORLDPATH = .
LIBOVRPATH = ../../LibOVR
COMMONSRCPATH = ../CommonSrc
3RDPARTYPATH = ../../3rdParty
INCPATH = -I. -I.. -I$(COMMONSRCPATH) -I$(LIBOVRPATH)/Include -I$(LIBOVRPATH)/Src
OBJPATH = ./Obj/Linux/$(RELEASETYPE)/$(SYSARCH)
CXX_BUILD = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJPATH)/
####### Files
LIBS = -L$(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH) \
-lovr \
-ludev \
-lpthread \
-lGL \
-lX11 \
-lXrandr \
-lrt
TARGET = ./Release/OculusWorldDemo_$(SYSARCH)_$(RELEASETYPE)
####### Rules
all: $(TARGET)
OCULUSWORLD_SOURCE = $(OCULUSWORLDPATH)/OculusWorldDemo.cpp \
$(OCULUSWORLDPATH)/OculusWorldDemo_Scene.cpp \
$(OCULUSWORLDPATH)/Player.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Util/RenderProfiler.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Util/OptionMenu.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Linux_Gamepad.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Linux_Platform.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Platform/Platform.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_Device.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_GL_Device.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_LoadTextureDDS.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_LoadTextureTGA.cpp \
$(OCULUSWORLDPATH)/../CommonSrc/Render/Render_XmlSceneLoader.cpp \
$(OCULUSWORLDPATH)/../../3rdParty/TinyXml/tinyxml2.cpp
OCULUSWORLD_OBJECTS = $(patsubst $(OCULUSWORLDPATH)%.cpp,$(OBJPATH)%.o,$(OCULUSWORLD_SOURCE))
OBJECTS = $(OTHER_OBJECTS) $(OCULUSWORLD_OBJECTS)
$(OBJPATH)/%.o: %.cpp
-mkdir -p $(dir $#)
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $# $<
$(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH)/libovr.a:
$(MAKE) -C $(LIBOVRPATH) DEBUG=$(DEBUG)
lib: $(LIBOVRPATH)/Lib/Linux/$(RELEASETYPE)/$(SYSARCH)/libovr.a
run: $(TARGET)
$(TARGET)
$(TARGET): $(OBJECTS) lib
-mkdir -p $(dir $#)
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)
clean:
-$(DELETEFILE) $(OBJECTS)
-$(DELETEFILE) $(TARGET)
cleanall:
-$(DELETEFILE) $(OBJECTS)
-$(DELETEDIR) ./Release/*
xxx:~/Desktop/ing$ make
true
make -C ./LibOVR
make[1]: Entering directory `/home/bosch3d/Desktop/ing/LibOVR'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/LibOVR'
make -C ./Samples/OculusWorldDemo
make[1]: Entering directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
mkdir -p Release/
g++ -O1 -o ./Release/OculusWorldDemo_x86_64_Release ./Obj/Linux/Release/x86_64/OculusWorldDemo.o ./Obj/Linux/Release/x86_64/OculusWorldDemo_Scene.o ./Obj/Linux/Release/x86_64/Player.o ./Obj/Linux/Release/x86_64/../CommonSrc/Util/RenderProfiler.o ./Obj/Linux/Release/x86_64/../CommonSrc/Util/OptionMenu.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Linux_Gamepad.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Linux_Platform.o ./Obj/Linux/Release/x86_64/../CommonSrc/Platform/Platform.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_Device.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_GL_Device.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_LoadTextureDDS.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_LoadTextureTGA.o ./Obj/Linux/Release/x86_64/../CommonSrc/Render/Render_XmlSceneLoader.o ./Obj/Linux/Release/x86_64/../../3rdParty/TinyXml/tinyxml2.o -L../../LibOVR/Lib/Linux/Release/x86_64 -lovr -ludev -lpthread -lGL -lX11 -lXrandr -lrt
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::~OculusWorldDemoApp()':
OculusWorldDemo.cpp:(.text+0x756): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text+0x7d6): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text+0x836): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text+0x843): undefined reference to `cv::Mat::deallocate()'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::RenderEyeView(ovrEyeType)':
OculusWorldDemo.cpp:(.text+0x9064): undefined reference to `ReadDataRunML::run(bool)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `cv::Mat::~Mat()':
OculusWorldDemo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x89): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x79): undefined reference to `cv::fastFree(void*)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::~ReadDataRunML()':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0xa6): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x120): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x144): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLD2Ev[_ZN13ReadDataRunMLD5Ev]+0x154): undefined reference to `cv::Mat::deallocate()'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::ReadDataRunML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, int)':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1a3): undefined reference to `cv::String::allocate(unsigned long)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1eb): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&, int, int, int, cv::String const&, char, char)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1f8): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x20b): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x2ec): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x3db): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x4c7): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x5bf): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x6b8): undefined reference to `cv::fastFree(void*)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x6c7): undefined reference to `cv::Formatter::get(int)'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x7c1): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x861): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x86e): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x882): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x88f): undefined reference to `cv::Mat::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x929): undefined reference to `cv::String::deallocate()'
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x975): undefined reference to `cv::String::deallocate()'
collect2: ld returned 1 exit status
make[1]: *** [Release/OculusWorldDemo_x86_64_Release] Error 1
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
make: *** [Samples/OculusWorldDemo/Release/OculusWorldDemo_x86_64_Release] Error 2
xxx:~/Desktop/ing$
I have added:
-lopencv_core \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \
Now the Errors are:
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `OculusWorldDemoApp::RenderEyeView(ovrEyeType)':
OculusWorldDemo.cpp:(.text+0x9064): undefined reference to `ReadDataRunML::run(bool)'
./Obj/Linux/Release/x86_64/OculusWorldDemo.o: In function `ReadDataRunML::ReadDataRunML(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, double, int, int)':
OculusWorldDemo.cpp:(.text._ZN13ReadDataRunMLC2ESsidii[_ZN13ReadDataRunMLC5ESsidii]+0x1eb): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&, int, int, int, cv::String const&, char, char)'
collect2: ld returned 1 exit status
make[1]: *** [Release/OculusWorldDemo_x86_64_Release] Error 1
make[1]: Leaving directory `/home/bosch3d/Desktop/ing/Samples/OculusWorldDemo'
make: *** [Samples/OculusWorldDemo/Release/OculusWorldDemo_x86_64_Release] Error 2
ReadDataRunML is a class added by myself. How should I add it to MakeFile?
You need to add the opencv libraries to the list of libs you link with:
Add to the LIBS section of your MakeFile:
-lopencv_core \
and, depending on which opencv features you use, you may need one or more of the following:
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_video \
-lopencv_objdetect \
The unresolved externals are simply because the linker doesn't know where to look for them. Also, make sure your opencv library path is either in your lib path or add it to the libpath used by the linker. You can add to the library path with the -L option, e.g. -LMyLocalPathToOpenCV (rather than hard-coding it where you add it to the linker options, you'll probably want define it and use a macro to refer to it, to keep your makefile cleaner, e.g. $(OPENCV_LIB_PATH)).