我是cppuTest的新手,实际上我正在尝试在CppuTest根目录中构建./examples。源代码和测试文件的编译没有问题,但我在最后的链接阶段遇到了这个错误:
C:\CppUTest\cpputest-3.7.1\examples>make
compiling AllTests.cpp
compiling CircularBufferTest.cpp
compiling EventDispatcherTest.cpp
compiling HelloTest.cpp
compiling MockDocumentationTest.cpp
compiling PrinterTest.cpp
compiling CircularBuffer.cpp
compiling EventDispatcher.cpp
compiling Printer.cpp
compiling hello.c
Building archive lib/libCppUTestExamples.a
a - objs/ApplicationLib/CircularBuffer.o
a - objs/ApplicationLib/EventDispatcher.o
a - objs/ApplicationLib/Printer.o
a - objs/ApplicationLib/hello.o
Linking CppUTestExamples_tests
../lib/libCppUTest.a(UtestPlatform.cpp.obj): In function `PThreadMutexCreate':
c:/CppUTest/cpputest-3.7.1/src/Platforms/Gcc/UtestPlatform.cpp:248: undefined reference to `_imp__pthread_mutex_init'
../lib/libCppUTest.a(UtestPlatform.cpp.obj): In function `PThreadMutexLock':
c:/CppUTest/cpputest-3.7.1/src/Platforms/Gcc/UtestPlatform.cpp:255: undefined reference to `_imp__pthread_mutex_lock'
../lib/libCppUTest.a(UtestPlatform.cpp.obj): In function `PThreadMutexUnlock':
c:/CppUTest/cpputest-3.7.1/src/Platforms/Gcc/UtestPlatform.cpp:260: undefined reference to `_imp__pthread_mutex_unlock'
../lib/libCppUTest.a(UtestPlatform.cpp.obj): In function `PThreadMutexDestroy':
c:/CppUTest/cpputest-3.7.1/src/Platforms/Gcc/UtestPlatform.cpp:266: undefined reference to `_imp__pthread_mutex_destroy'
collect2.exe: error: ld returned 1 exit status
make: *** [CppUTestExamples_tests] Error 1我在Windows7上使用的是MinGW,MinGW也包含pthread.a库。我的makefil如下所示:
#---------
#
# CppUTest Examples Makefile
#
#----------
#Set this to @ to keep the makefile quiet
ifndef SILENCE
SILENCE = @
endif
#--- Inputs ----#
COMPONENT_NAME = CppUTestExamples
CPPUTEST_HOME = ..
CPPUTEST_USE_EXTENSIONS = Y
CPP_PLATFORM = Gcc
CFLAGS = -Dmalloc=cpputest_malloc -Dfree=cpputest_free
CPPFLAGS =
GCOVFLAGS = -fprofile-arcs -ftest-coverage
LDFLAGS = -lpthread
#USER_LIBS = -lpthread
# This line is overriding the default new macros. This is helpful
# when using std library includes like <list> and other containers
# so that memory leak detection does not conflict with stl.
CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include ApplicationLib/ExamplesNewOverrides.h
SRC_DIRS = \
ApplicationLib
TEST_SRC_DIRS = \
AllTests
INCLUDE_DIRS =\
.\
ApplicationLib\
$(CPPUTEST_HOME)/include\
include $(CPPUTEST_HOME)/build/MakefileWorker.mk如您所见,pthread lib被提供给带有LDFLAGS的链接器。
有类似经历的人吗?或者可能知道问题出在哪里?将会对任何提示表示感谢!
发布于 2015-08-05 15:28:42
感谢“基思·马歇尔”和“疯狂科学家”
所以不是LDFLAGS = -lpthread
我使用:
LD_LIBRARIES += -lpthread并将此行直接放在前面:
include $(CPPUTEST_HOME)/build/MakefileWorker.mk现在它起作用了。
发布于 2016-07-12 08:41:48
可以在Catalogue of Built-In Rules中看到
链接单个对象文件的
通过C编译器运行链接器(通常称为ld),从n.o自动生成n。使用的精确配方是:
$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)
和Variables Used by Implicit Rules
低版本标志
当编译器应该调用链接器ld (如-L )时,要给它们的额外标志。应该将库(-lfoo)添加到LDLIBS变量中。
因此,在这种情况下,应该将-lpthread设置或添加到LDLIBS,而不是LDFLAGS。
https://stackoverflow.com/questions/31804587
复制相似问题