当我试图构建我的程序时,链接器失败了,告诉我对PCRE函数有未定义的引用。
我已经链接了libpcre.a并将其所在的目录添加到搜索路径中,还将头文件添加到搜索路径中,甚至通过配置cmake、关闭PCRECPP以防万一并在目录上运行make来多次重建PCRE。似乎我无法修复它,我相信这是一个配置问题。也许是我做的傻事吧!

mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
gcc.exe    -c -g -Wall -I/C/Users/One/Documents/Programming/C/Libraries/pcre-8.12 -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.c
main.c: In function 'main':
main.c:278:5: warning: passing argument 3 of 'pcre_compile' from incompatible pointer type [enabled by default]
c:/Users/One/Documents/Programming/C/Libraries/pcre-8.12/pcre.h:282:21: note: expected 'const char **' but argument is of type 'char **'
main.c:282:5: warning: passing argument 3 of 'pcre_compile' from incompatible pointer type [enabled by default]
c:/Users/One/Documents/Programming/C/Libraries/pcre-8.12/pcre.h:282:21: note: expected 'const char **' but argument is of type 'char **'
main.c: In function 'getFileList':
main.c:231:1: warning: control reaches end of non-void function [-Wreturn-type]
main.c: In function 'getFileServer':
main.c:205:1: warning: control reaches end of non-void function [-Wreturn-type]
mkdir -p dist/Debug/MinGW-Windows
gcc.exe     -o dist/Debug/MinGW-Windows/project1 build/Debug/MinGW-Windows/main.o -L/C/Users/One/Documents/Programming/C/Libraries/pcre-8.12/lib -lpcre
build/Debug/MinGW-Windows/main.o: In function `runRegex':
C:\Users\One\Documents\Programming\C\Projects\project1/main.c:174: undefined reference to `_imp__pcre_exec'
build/Debug/MinGW-Windows/main.o: In function `main':
C:\Users\One\Documents\Programming\C\Projects\project1/main.c:278: undefined reference to `_imp__pcre_compile'
C:\Users\One\Documents\Programming\C\Projects\project1/main.c:282: undefined reference to `_imp__pcre_compile'
collect2: ld returned 1 exit status

最佳答案

出于某种原因,编译器希望有一个动态库——一旦我在CMake中设置了这个选项,它就可以正常工作了。(尽管我仍然不知道如何让它接受构建的静态库,但是我可以通过命令行使用gcc来实现)

关于c - Netbeans对PCRE函数提供了 undefined reference ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8275922/

10-09 01:00