Ich migriere vom Makefile, das automatisch von Eclipse erstellt wurde, in ein manuelles Makefile. Es funktioniert mit Eclipse, aber nicht mit meinem. Das ist die Compilerausgabe:Undefinierter Verweis auf 'testing :: UnitTest :: GetInstance() "
13:54:30 **** Incremental Build of configuration Debug for project MY_PROJECT ****
make -f ../build/makefile all
Building file: ../src/TestLauncher.cpp
g++ -std=c++11 -I"../src" -I"../src/Common" -I"../src/Common/COMPUTATION" -I"../src/Common/DATA_ACQUISITION" -I"/usr/include/mysql" -I"/usr/include/gtest" -O0 -g3 -pg -Wall -Wextra -fmessage-length=0 --coverage -fPIC -MMD -MP -MF"../bin/objs/TestLauncher.d" -MT"../bin/objs/TestLauncher.o" -o "../bin/objs/TestLauncher.o" "../src/TestLauncher.cpp"
/tmp/ccrDQ0Bm.o: In function `main':
/home/user/workspace/MY_PROJECT/build/../src/TestLauncher.cpp:13: undefined reference to `testing::InitGoogleTest(int*, char**)'
../build/makefile:165: recipe for target '../bin/objs/TestLauncher.o' failed
/tmp/ccrDQ0Bm.o: In function `RUN_ALL_TESTS()':
/usr/include/gtest/gtest.h:2288: undefined reference to `testing::UnitTest::GetInstance()'
/usr/include/gtest/gtest.h:2288: undefined reference to `testing::UnitTest::Run()'
collect2: error: ld returned 1 exit status
make: *** [../bin/objs/TestLauncher.o] Error 1
13:54:31 Build Finished (took 989ms)
ich habe für diesen Fehler gesucht und es scheint immer mit -lgtest unter Linker-Flags nicht verwandt sein zu sein. ich bin, aber trotzdem dieser Fehler passiert ist, nicht an dem Linker, sondern an der Übersetzungsphase. Deshalb Ich verstehe nicht, warum dieses Problem ausgelöst wird.
Ich habe auch gtest
Bibliothek kompiliert, die in /usr/lib/
ist : Wie gesagt, es funktioniert mit dem Makefile von Eclipse.
Das ist meine Make-Datei:
-include ../makefile.init
RM := rm -rf
EXECUTABLE_NAME := MY_PROJECT
FLAGS := -O0 -g3 -pg -Wall -Wextra -fmessage-length=0 --coverage -fPIC#-v
C++_DEPS :=
C_DEPS :=
CC_DEPS :=
CPP_DEPS :=
CXX_DEPS :=
C_UPPER_DEPS :=
EXECUTABLES := ../bin/$(EXECUTABLE_NAME)
LIBS_SERVER := -ldl -lpthread -lgtest -lboost_date_time -lmysqlclient -lboost_filesystem -lboost_system
INCLUDES_LIB_SERVER := -L /usr/lib/mysql -L /usr/lib/boost
CPP_SRCS += \
../src/TestLauncher.cpp \
../src/Common/DATA_ACQUISITION/DATA_ACQUISITION_test.cpp
OBJS += \
../bin/objs/TestLauncher.o \
../bin/objs/DATA_ACQUISITION_test.o
CPP_DEPS += \
../bin/objs/TestLauncher.d \
../bin/objs/DATA_ACQUISITION_test.d
INCLUDES_SERVER += \
-I"../src" \
-I"../src/Common" \
-I"../src/Common/COMPUTATION" \
-I"../src/Common/DATA_ACQUISITION" \
-I"/usr/include/mysql" \
-I"/usr/include/gtest"
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif
-include ../makefile.defs
###############################################################################
# TARGETS
###############################################################################
# All Target
all: $(EXECUTABLES)
test: FLAG=-DTEST
test: all
../bin/$(EXECUTABLE_NAME): $(OBJS)
@echo 'Building target: [email protected]'
@echo 'Invoking: Cygwin C++ Linker'
g++ $(FLAGS) -o"../bin/$(EXECUTABLE_NAME)" $(OBJS) $(INCLUDES_LIB_SERVER) $(LIBS_SERVER)
@echo 'Finished building target: [email protected]'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS) $(OBJS_RT) $(C++_DEPS) $(EXECUTABLES)$(CC_DEPS)$(C_DEPS)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS) ../bin/MY_PROJECT
[email protected] ' '
.PHONY: all clean dependents
.SECONDARY:
###############################################################################
# COMPILE --> OBJS
###############################################################################
../bin/objs/%.o: ../src/%.cpp
@echo 'Building file: $<'
g++ -std=c++11 $(INCLUDES_SERVER) $(FLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "[email protected]" "$<"
@echo 'Finished building: $<'
@echo ' '
../bin/objs/%.o: ../src/Common/%.cpp
@echo 'Building file: $<'
g++ -std=c++11 $(INCLUDES_SERVER) $(FLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "[email protected]" "$<"
@echo 'Finished building: $<'
@echo ' '
../bin/objs/%.o: ../src/Common/COMPUTATION/%.cpp
@echo 'Building file: $<'
g++ -std=c++11 $(INCLUDES_SERVER) $(FLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "[email protected]" "$<"
@echo 'Finished building: $<'
@echo ' '
../bin/objs/%.o: ../src/Common/DATA_ACQUISITION/%.cpp
@echo 'Building file: $<'
g++ -std=c++11 $(INCLUDES_SERVER) $(FLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "[email protected]" "$<"
@echo 'Finished building: $<'
@echo ' '
Jede Idee, was falsch ist?
Ich könnte natürlich falsch sein, aber IMO dies gilt nicht, da der Linker nicht ausgeführt wird. Der Fehler ist bei der Kompilierungsphase und -flags werden dort nicht einmal verwendet. –