在CentOS中编译c源文件,遇到(.text+0x20): undefined reference to `main'
2017-12-05 23:18
465 查看
这是我的bat文件
gcc -c ./shared/108/io.c -o io-1.o 2>>error-1.txt
gcc -I ./shared/108 -c ./000/082/975/CWE190_Integer_Overflow__int_connect_socket_add_02.c -o io-2.o 2>>error-2.txt
gcc -I ./shared/108 -g io-2.o io-1.o 2>>error-3.txt
第一步和第二步都没有出错,第三步就报错:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
也求教了很多人,有人问我是不是根本就没有写main()函数,这也就尴尬了,我真的写了,怎么就找不到。
c源文件,部分代码如下:
/* Below is the main(). It is only used when building this testcase on
its own for testing or for building a binary to use in testing binary
analysis tools. It is not used when compiling all the testcases as one
application, which is how source code analysis tools are tested. */
#ifdef INCLUDEMAIN
main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_bad();
printLine("Finished bad()");
#endif /* OMITBAD */
}
#endif
接下来怀疑是返回值的问题,又添加了返回类型,有查过引用的标准库,最后运用的控制变量法,发现了问题
是宏定义出了错误
#ifdef INCLUDEMAIN
......
#endif
#ifdef 语句1
语句2
#endif
这种语句的意思是如果存在宏定义了语句1则执行语句2,它的作用是可以用它区隔一些与特定头文件、程序库和其他文件版本有关的代码。
这代码是用于测试使用的,我看不出开发者的用意,就是验证是否存在INCLUDEMAIN这个宏定义,我也查找过了,不存在这个定义,所以自然不执行语句2,也就找不到main函数入口了,删除这条语句,走起~一切ok。
main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_bad();
printLine("Finished bad()");
#endif /* OMITBAD */
}
得到正常运行结果:
gcc -c ./shared/108/io.c -o io-1.o 2>>error-1.txt
gcc -I ./shared/108 -c ./000/082/975/CWE190_Integer_Overflow__int_connect_socket_add_02.c -o io-2.o 2>>error-2.txt
gcc -I ./shared/108 -g io-2.o io-1.o 2>>error-3.txt
第一步和第二步都没有出错,第三步就报错:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
也求教了很多人,有人问我是不是根本就没有写main()函数,这也就尴尬了,我真的写了,怎么就找不到。
c源文件,部分代码如下:
/* Below is the main(). It is only used when building this testcase on
its own for testing or for building a binary to use in testing binary
analysis tools. It is not used when compiling all the testcases as one
application, which is how source code analysis tools are tested. */
#ifdef INCLUDEMAIN
main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_bad();
printLine("Finished bad()");
#endif /* OMITBAD */
}
#endif
接下来怀疑是返回值的问题,又添加了返回类型,有查过引用的标准库,最后运用的控制变量法,发现了问题
是宏定义出了错误
#ifdef INCLUDEMAIN
......
#endif
#ifdef 语句1
语句2
#endif
这种语句的意思是如果存在宏定义了语句1则执行语句2,它的作用是可以用它区隔一些与特定头文件、程序库和其他文件版本有关的代码。
这代码是用于测试使用的,我看不出开发者的用意,就是验证是否存在INCLUDEMAIN这个宏定义,我也查找过了,不存在这个定义,所以自然不执行语句2,也就找不到main函数入口了,删除这条语句,走起~一切ok。
main(int argc, char * argv[])
{
/* seed randomness */
srand( (unsigned)time(NULL) );
#ifndef OMITGOOD
printLine("Calling good()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_good();
printLine("Finished good()");
#endif /* OMITGOOD */
#ifndef OMITBAD
printLine("Calling bad()...");
CWE190_Integer_Overflow__int_connect_socket_add_02_bad();
printLine("Finished bad()");
#endif /* OMITBAD */
}
得到正常运行结果:
相关文章推荐
- Linux下eclipse编译C/C++程序遇到 undefined reference to `pthread_create'的异常解决办法
- 编译C++程序遇到错误:undefined reference to `*::*
- 编译android5.1 源码 遇到错误undefined reference to 'register_android_system_OsConstants(_JNIEnv*)'
- [CentOS]CentOS下编译CPP文件时报错[undefined reference to `__gxx_personality_v0' collect2: ld]的解决办法
- 解决gcc 编译时报错"undefined reference to 'main'" 问题
- 编译时遇到 "Undefined reference to vtable for ***" 错误怎么办?
- 编译Ralink SDK时碰到的奇怪错误(undefined reference to `main')的解决办法
- 编译Ralink SDK时碰到的奇怪错误(undefined reference to `main')的解决办法
- cc编译cpp遇到undefined reference to `__gxx_personality_v0'
- linux编译安装php5.4遇到错误:undefined reference to `libiconv_open'
- linux下gcc编译使用opencv的源文件时报错的处理:undefined reference to symbol '_ZNSsD1Ev@@GLIBCXX_3.4'
- Linux下编译C++程序遇到错误:undefined reference to '***'
- CentOS 6.5 编译 PHP-7 报错:undefined reference to `libiconv_open 无法编译 PHP libiconv
- Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错,
- CentOS6下Sphinx2.1.9编译错误undefined reference to 'libiconv'
- 编译:splint 遇到的问题: undefined reference to `yywrap'
- mingw编译SDL_gfx库时遇到undefined reference to 'GFX_ALPHA_ADJUST_ARRAY'问题的解决方法
- VIVADO中SDK新建工程编译出错——undefined reference to 'main'
- 编译时遇到错误:undefined reference to XXXXXX
- gcc undefined reference to '__stack_chk_fail'【操作系统开发编译中遇到的问题】