Linux Gcc编译错误(转载)

转自:http://www.linuxidc.com/Linux/2012-01/52153.htm

Linux系统下的c编程与Windows有所不同,如果你在用gcc编译代码的时候提示‘for’ loop initial declarations are only allowed in C99 mode,可能就是因为你在loop循环比如for中使用未预先定义的变量,比如:

for(int i=0;i<10;i++)

{

}

这种写法在vc里是没有错的,而子gcc就会提示错误,要求遵守c89标准,c89标准是不支持上述写法的。如果你非要这么写可以这样编译,使用c99标准:

gcc helo.c -std=c99 -o hello

当然,你也可以先定义i变量。

int i;

for(i=0;i<10;i++)

{

}

这样再编译就不会再提示‘for’ loop initial declarations are only allowed in C99 mode这样的错误了

时间: 2024-08-09 22:00:47

Linux Gcc编译错误(转载)的相关文章

Linux GCC编译警告:Clock skew detected. 错误解决办法

今天在虚拟机上用GCC编译一个程序的时候,出现了下面的错误: make: warning: Clock skew detected. Your build may be incomplete 试了make clean后再make,仍然是同样的问题,最后发现这个错误的原因在于系统时间比文件修改时间早,看了下我的系统时间竟然还是2012-01-13,而今天都已经是2012-01-31呢,于是修改时间后重新编译,问题解决. Linux下用date命令可查询和修改系统时间(root权限才可修改) 1 d

Linux gcc 编译日记

gcc 编译器是众多编译器组合入口,例如在编译 .cpp 文件时,使用c++ 编译器,编译.c 文件时,使用c编译器. 在编译c++程序时, 库文件与头文件可通过 -L[dir] 指定库目录 , -l[name] 指定库文件名称.指定库文件名称时,需按照指定范式.例如库文件 libabc.a ,  [lib]abc[.a] 中括号部份默认乎略, 此时库文件名称为: abc ,因此在gcc 编译时,通过 -labc 来加载该库. 通常c++ 程序会用到标准库,例如代码中包含 string#incl

gcc编译错误:DSO missing from command line

在用gcc 编译连接的时候,可能会遇到类似以下的错误: /usr/bin/ld: test_desktop_utils-test-desktop-utils.o: undefined reference to symbol 'g_desktop_app_info_get_filename'//usr/lib/x86_64-linux-gnu/libgio-2.0.so.0: error adding symbols: DSO missing from command line 这个问题一般是由于

linux gcc 编译动态类库(.so)和静态类库(.a)

我的编译环境 ubuntu desktop 16.04 一:测试代码 测试有3个文件:AB.h,AB.c,test.c //AB.h void hello(); //AB.c #include <stdio.h> void hello() { printf("hello from AB.c \n"); } //test.c #include <stdio.h> #include "AB.h" void main(void) { printf(

linux gcc编译多个文件的方法

假设源程序文件名为test.c. 1. 无选项编译链接 用法:#gcc test.c 作用:将test.c预处理.汇编.编译并链接形成可执行文件.这里未指定输出文件,默认输出为a.out. 2. 选项 -o 用法:#gcc test.c -o test 作用:将test.c预处理.汇编.编译并链接形成可执行文件test.-o选项用来指定输出文件的文件名. 3. 选项 -E 用法:#gcc -E test.c -o test.i 作用:将test.c预处理输出test.i文件. 4. 选项 -S

Linux GCC编译使用动态、静态链接库 (转)

原文出处:http://blog.csdn.net/a600423444/article/details/7206015 在windows下动态链接库是以.dll后缀的文件,二在Linux中,是以.so作后缀的文件. 动态链接库的好处就是节省内存空间. 1.Linux下创建动态链接库 在使用GCC编译程序时,只需加上-shared选项即可,这样生成的执行程序即为动态链接库. 例如有文件:hello.c x.h main.c [plain] view plaincopy 编译:gcc hello.

mac gcc 编译错误 基础问题

mac gcc  Undefined symbols for architecture x86_64 "std::__1: // Undefined symbols for architecture x86_64: "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from: std::__1::basic_ostream<char, std::__1::char_tra

linux gcc编译protocol

p { margin-bottom: 0.25cm; line-height: 120% } a:link { } gcc -c test.pb-c.c//生成test.pb-c.o文件 gcc -c udp_socket_server.c//生成udp_socket_server.o gcc -o test1 udp_socket_server.o test.pb-c.o -lprotobuf-c ./test1 protoc-c --c_out=./ test.proto

Linux gcc链接动态库出错:LIBRARY_PATH和LD_LIBRARY_PATH的区别

昨天在自己的CentOs7.1上写makefile的时候,发现在一个C程序在编译并链接一个已生成好的lib动态库的时候出错.链接命令大概是这样的: [[email protected] tcpmsg]# gcc -o hello main.c -lmyhello /usr/bin/ld: cannot find -lmyhello collect2: error: ld returned 1 exit status 1 gcc链接动态库时的搜索路径 自以为在当前工程中设置好了环境变量 LD_LI