2012-12-25 67 views
1

我想在Eclipse中編譯我的項目。主要()這裏首先定義

但是,它表示main()定義了多次。 I grep'd我的項目目錄,它發現只有一個定義main(),在main.cpp中。

顯然它在別的地方。可能是我鏈接到的目錄。

我聯繫的唯一迪爾斯到是:

-ljson_linux-gcc-4.5.2_libmt 

編譯器的輸出是:

make all 
Building file: ../src/main.cpp 
Invoking: GCC C++ Compiler 
g++ -Ijson_linux-gcc-4.5.2_libmt -I/usr/include/mysql -I/usr/include/jsoncpp-src-0.5.0/include -O0 -g3 -Wall -c -fmessage-length=0 -Ijson_linux-gcc-4.5.2_libmt -MMD -MP -MF"src/main.d" -MT"src/main.d" -o"src/main.o" "../src/main.cpp" 
Finished building: ../src/main.cpp 

Building target: Atms 
Invoking: GCC C++ Linker 
g++ -L-L/usr/include/jsoncpp-src-0.5.0/include/ -o"Atms" ./src/atmstypes.o ./src/base64.o ./src/hregex.o ./src/libparser.o ./src/log.o ./src/main.o ./src/serv.o ./src/sqlfeeder.o ./src/teleindex.o ./src/telepipe.o ./src/telesharedobject.o ./src/treet.o ./src/ttable.o -l-ljson_linux-gcc-4.5.2_libmt 
./src/serv.o: In function `main': 
/usr/include/c++/4.4/new:101: multiple definition of `main' 
./src/main.o:/home/idan/workspaceCpp/Atms/Debug/../src/main.cpp:12: first defined here 
/usr/bin/ld: cannot find -l-ljson_linux-gcc-4.5.2_libmt 
collect2: ld returned 1 exit status 
make: *** [Atms] Error 1 

main.cpp中:

#include <stdio.h> 
#include <stdlib.h> 
#include <regex.h> 
#include <iostream> 
#include <string.h> 
#include <string> 
#include "../h/hregex.h" 
using namespace std; 


string s = "this and7 that"; 
int main(int argc,char** argv){ 
    cout << hregex::InitRegex() << endl; 
    cout << hregex::CheckHostnameField(s)<< "= this and7 that" << endl; 
    s = "this and7 that"; 
    cout << hregex::CheckURLField(s)<< "= this and7 that" << endl; 
    s = "/lol/idan.html"; 
    cout << hregex::CheckURLField(s)<< "= /lol/idan.html" << endl; 
    s = "/lol2#/idan.html"; 
    cout << hregex::CheckURLField(s)<< "= /lol2#/idan.html" << endl; 
    return 0; 
} 

我怎樣才能防止錯誤出現?

+0

eclipse會告訴你它在哪裏定義兩次?輸出conosle中的任何內容? – thescientist

+0

添加了輸出: - \ –

+2

任何機會,您是否在'main.c'中包含了任何'.c'文件而不是'.h'頭文件? –

回答

2

g ++說serv.o有一個主要功能。

如果實際上沒有main()它serv.cpp,請檢查includes,也許你做了一個糟糕的#include幷包含一個.cpp而不是.h?

作爲一個額外注: 它試圖綁定對庫 「-ljson_linux-GCC-4.5.2_libmt」

所以在鏈接命令 「-1- ljson_linux-GCC-4.5.2_libmt」線。刪除您的配置中的-l