[英]What Is Causing The Undefined Reference In make?
以下make輸出顯示了一個未定義的引用,但我不確定是什么原因引起的。 有人可以幫忙嗎?
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe
make[2]: Entering directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f build/Debug/Cygwin_4.x-Windows/main.o.d
gcc -std=c99 -c -g -I../mongodb-mongo-c-driver/src/\*.c -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.c
mkdir -p dist/Debug/Cygwin_4.x-Windows
gcc -std=c99 -o dist/Debug/Cygwin_4.x-Windows/mongodrivertest build/Debug/Cygwin_4.x-Windows/main.o
nbproject/Makefile-Debug.mk:61: recipe for target `dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe' failed
make[2]: Leaving directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
nbproject/Makefile-Debug.mk:58: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/g/workspace/c_cpp/MongoDriverTest'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
build/Debug/Cygwin_4.x-Windows/main.o: In function `main':
/cygdrive/g/workspace/c_cpp/MongoDriverTest/main.c:19: undefined reference to `_mongo_connect'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin_4.x-Windows/mongodrivertest.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
這是我的main.c的內容:
#include <stdio.h>
#include <stdlib.h>
#include "../mongodb-mongo-c-driver/src/mongo.h"
int main(int argc, char** argv) {
int status;
mongo conn[1];
status=mongo_connect(conn, "127.0.0.1", 27017);
return EXIT_SUCCESS;
}
它在兩天前可以正常工作,我重新安裝了操作系統,現在它不再正常工作,而且我似乎也找不到原因。 mongo.h存在,mongo.o也在那里。 mongo_connect在mongo.c中。 任何想法?
您的鏈接行是:
gcc -std=c99 -o dist/Debug/Cygwin_4.x-Windows/mongodrivertest build/Debug/Cygwin_4.x-Windows/main.o
它沒有告訴GCC從哪里收集mongo_connect()
。 您需要在命令行上指定Mongo庫。
給定源代碼中的include行:
#include "../mongodb-mongo-c-driver/src/mongo.h"
您可以添加選項:
-L../mongodb-mongo-c-driver/lib -lmongo
到鏈接線。 位置和庫名稱都是猜測。 那將從指定目錄中拾取libmongo.dll
或libmongo.lib
。
如果在../mongodb-mongo-c-driver
目錄下的某個位置找不到該庫,則可能必須構建並安裝它。 或者,它可能已經安裝了,您只需要確保引用的安裝位置正確即可。
另外,通常應避免使用類似於源代碼中的路徑名。 您應指定:
#include "mongo.h"
並提供編譯行選項以指定查找位置:
-I../mongodb-mongo-c-driver/src
另請參見: 相對路徑(如#include "../include/header.h"
對標頭有什么#include "../include/header.h"
? 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.