main()首先在这里定义
main() first defined here
我正试图在Eclipse中编译我的项目。
然而,它说main()
被定义了不止一次。我grep
查看了我的项目目录,它在main.cpp中只找到了main()
的一个定义。
显然它在其他地方。也许是我链接的目录。
我链接的唯一目录是:
-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;
}
如何防止出现错误?
g++说serv.o有一个主要功能。
如果实际上没有main((it serv.cpp,请检查includes,也许你做了一个错误的#include,并包含了.cpp而不是.h?
作为补充说明:它试图绑定库"-ljson_linux-gcc-4.55.2_libmt">
因此,链接命令行中有"-ljson_linux-gcc-4.55.2_libmt"。删除配置中的-l
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- 在类定义之后定义一个私有方法
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 如何在自定义类中启用'auto loops'?
- 这个c++代码是如何在没有定义函数的情况下运行的
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- 为什么thread_local变量在这里从未初始化?
- 为什么我必须在这里使用dynamic_cast
- C++ 中的自定义异常:在哪里定义它们?
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 不允许在类定义之外重写
- 在自定义 std::vector-like 容器中处理指针和非指针模板类型的最佳方法是什么?
- ld: foo.o:foo.h:6 'bar' 的多重定义 foo.h:6: 首先在这里定义
- *在这里定义什么
- 代码块 int main 之前在这里定义
- C ++中的构建错误,未定义的符号,在这里尝试了其他答案,无法弄清楚
- 为什么链接器在这里不产生多个定义错误?
- main()首先在这里定义