//改完后的程序如下,假如文件名为test.cpp
//编译时用这个语句 g++ -o test test.cpp
//在我自己的Linux环境试过好用
//另外,楼主可以用man getuid来看帮助
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
using namespace std;
int main() {
cout << getuid() << endl;
return 0;
}
=================
你是什么linux版本??g++啥版本的?
====================
按我的方法报什么错??能把错再发一下不?
另外,你系统上装开发包了吧?
最简单的hello world能编译正确运行吗?
❷ 跪求linux大神 ---编译时报错
libopen-pal.so.4 估计是你的 LD_LIBRARY_PATH没有设置,也就是链接路径里面没有你这个文件所在的文件夹
export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/lib/XXX
来设值
❸ linux下编译程序源码,执行make命令时报错如图,有没有什么头绪或者建议,谢谢大神了
linux下所有软件源码包的安装方式一般都会在readme中有详细的官方说明,对于gerbv如下图所示
上述大部分内容对linux下所有软件包的安装都适用。
❹ linux 安装了gcc后编译软件报错
少组件,运行命令
如果是ubuntu的系统,直接运行sudo apt-get install build-essential libc6-dev
如果是fedora,yum install g++* gcc*
不过你gcc到装上没啊
要先弄个redhat9.0能用的yum源,具体你可以搜一下,然后终端输入命令,(root用户下)
yum install g++* gcc*
❺ linux下c语言操作MYSQL编译报错
#include<mysql/mysql.h>
#include<stdio.h>
#include<stdlib.h>
#define HOST "localhost"
#define USERNAME "用户名"
#define PASSWORD "密码"
#define DATABASE "指定的数据库"
#define SQL_QUERY "SELECT*FROM表名"
intmain(void)
{
MYSQLmysql;
MYSQL_ROWrow;
MYSQL_RES*result;
unsignedintnum_fields;
unsignedinti;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,HOST,USERNAME,PASSWORD,DATABASE,0,NULL,0))
{
printf("Connectionfailed,%s ",mysql_error(&mysql));
}
mysql_query(&mysql,"setnamesutf8");
if(!mysql_query(&mysql,SQL_QUERY))
{
result=mysql_store_result(&mysql);
if(!result)
{
perror("resulterror.");
exit(1);
}
num_fields=mysql_num_fields(result);
while(row=mysql_fetch_row(result))
{
for(i=0;i<num_fields;i++)
{
printf("%s ",row[i]);
}
printf(" ");
}
mysql_free_result(result);
}
mysql_close(&mysql);
return0;
}
编译命令:
gcc -o mysql_test mysql_test.c -lmysqlclient
运行命令:
./mysql_test
❻ lpc2103 报错aeabi_uidiv
解决思路:
1、这个错误提示说明是一个未定义引用的错误,根据__aeabi_uidivmod,和__aeabi_uidiv猜想应该是除法实现的问题(为什么就能得出是除法实现的问题?根据英文名吗?可是我查了下,没有这个英文。)。
2、这里用到了lib1funcs.S这个除法库文件,于是在里面搜索__aeabi_uidiv和__aeabi_uidivmod,找不到这两个关键字的定义。
说明应该是4.3.2版本的编译工具需要找这两个关键字的定义,但是找不到。
3、猜测应该是这个lib1funcs.S是比较老版本的库文件,可是这个较新版本的去哪找呢,除法运算在u-boot和Linux内核里肯定实现了,就到这两个里面去找这个文件。
4、4.3.2编译通过的两个项目版本分别是u-boot-2012.04.01以及linux-3.4.2,就到这两个项目中找,你会发现u-boot里面没有这个文件,u-boot肯定实现了,但是不是用这个来实现的,我们到linux内核里找:
find /work/projects/linux-3.4.2 -name "lib1funcs.S"
搜索结果:
./arch/arm/lib/lib1funcs.S
./arch/arm/boot/compressed/lib1funcs.S
登录后复制
5、/work/system/linux-3.4.2/arch/arm/lib/lib1funcs.S,这个文件应该就是我们找的库文件。
把他到项目里,然后make。
编译结果:
arm-linux-gcc -c -o lib1funcs.o lib1funcs.S
lib1funcs.S:36:27: error: linux/linkage.h: No such file or directory
lib1funcs.S:37:27: error: asm/assembler.h: No such file or directory
lib1funcs.S:38:24: error: asm/unwind.h: No such file or directory
Makefile:11: recipe for target 'lib1funcs.o' failed
make: *** [lib1funcs.o] Error 1
登录后复制
提示我们找不到这些头文件,对比以前的lib1funcs.S不需要这些头文件。
所以我们把头文件注释掉:
35 /*
36 #include <linux/linkage.h>
37 #include <asm/assembler.h>
38 #include <asm/unwind.h>
39 */
登录后复制
6、再次编译,出现如下错误:
arm-linux-gcc -c -o lib1funcs.o lib1funcs.S
lib1funcs.S: Assembler messages:
lib1funcs.S:181: Error: bad instruction `entry(__udivsi3)'
lib1funcs.S:182: Error: bad instruction `entry(__aeabi_uidiv)'
lib1funcs.S:183: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:207: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:208: Error: bad instruction `endproc(__udivsi3)'
lib1funcs.S:209: Error: bad instruction `endproc(__aeabi_uidiv)'
lib1funcs.S:211: Error: bad instruction `entry(__umodsi3)'
lib1funcs.S:212: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:226: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:227: Error: bad instruction `endproc(__umodsi3)'
lib1funcs.S:229: Error: bad instruction `entry(__divsi3)'
lib1funcs.S:230: Error: bad instruction `entry(__aeabi_idiv)'
lib1funcs.S:231: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:268: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:269: Error: bad instruction `endproc(__divsi3)'
lib1funcs.S:270: Error: bad instruction `endproc(__aeabi_idiv)'
lib1funcs.S:272: Error: bad instruction `entry(__modsi3)'
lib1funcs.S:273: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:293: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:294: Error: bad instruction `endproc(__modsi3)'
lib1funcs.S:356: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:357: Error: bad instruction `unwind(.pad #4)'
lib1funcs.S:358: Error: bad instruction `unwind(.save {lr})'
lib1funcs.S:363: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:364: Error: bad instruction `endproc(Ldiv0)'
Makefile:11: recipe for target 'lib1funcs.o' failed
make: *** [lib1funcs.o] Error 1
登录后复制
应该是去掉头文件引起的编译器对定义不理解。
对比老版本的lib1funcs开头有一些宏定义我们先加上:
#define ALIGN .align 4,0x90
#define __LINUX_ARM_ARCH__ 1
#define ENTRY(name) \
.globl name; \
ALIGN; \
name:
登录后复制
其中有entry的宏定义,我们可以猜想这些都是在头文件里的宏定义,其实你去linux内核里找这个头文件#include <linux/linkage.h>在这里就可以找到entry的宏定义。
7、再次编译,出现错误:
[email protected]:/work/test$ make
arm-linux-gcc -c -o lib1funcs.o lib1funcs.S
lib1funcs.S: Assembler messages:
lib1funcs.S:192: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:216: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:217: Error: bad instruction `endproc(__udivsi3)'
lib1funcs.S:218: Error: bad instruction `endproc(__aeabi_uidiv)'
lib1funcs.S:221: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:235: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:236: Error: bad instruction `endproc(__umodsi3)'
lib1funcs.S:240: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:277: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:278: Error: bad instruction `endproc(__divsi3)'
lib1funcs.S:279: Error: bad instruction `endproc(__aeabi_idiv)'
lib1funcs.S:282: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:302: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:303: Error: bad instruction `endproc(__modsi3)'
lib1funcs.S:365: Error: bad instruction `unwind(.fnstart)'
lib1funcs.S:366: Error: bad instruction `unwind(.pad #4)'
lib1funcs.S:367: Error: bad instruction `unwind(.save {lr})'
lib1funcs.S:372: Error: bad instruction `unwind(.fnend)'
lib1funcs.S:373: Error: bad instruction `endproc(Ldiv0)'
Makefile:11: recipe for target 'lib1funcs.o' failed
make: *** [lib1funcs.o] Error 1
登录后复制
unwind() 和unwind()的宏定义老版本里没有,怎么办呢?
全部注释掉:
#UNWIND(.fnend)
#ENDPROC(__modsi3)
登录后复制
8、再次编译,出现错误:
[email protected]:/work/test$ make
arm-linux-gcc -c -o lib1funcs.o lib1funcs.S
#arm-linux-ld -Ttext 0 -Tdata 0x30000000 start.o led.o uart.o init.o main.o -o sdram.elf
arm-linux-ld -T sdram.lds start.o led.o uart.o init.o main.o exception.o interrupt.o timer.o nor_flash.o my_printf.o string_utils.o lib1funcs.o -o sdram.elf
my_printf.o: In function `out_num':
my_printf.c:(.text+0x120): undefined reference to `__aeabi_uidivmod'
lib。
LPC2103
LP
❼ 当编译 2.6.32.2 linux内核时,出现这样的报错
这提示的是内核网络驱动源程序中的语法错误,如果你没对下载的linux源码包做任何修改,那么按理说是不应该有语法错误的。出现这样的情况,我认为可能是你所安装的编译器gcc版本不合适,可以查一下编译2.6.32.2的内核对应的gcc版本,重新安装一下再试试。
❽ Linux 0.11内核编译错误记录
现象1: 提示gas gld 比识别
措施: gnu编译器发展到后来,越来越流行,更多使用别名为 as ld gcc等.
现象2: 提示字节对齐需要是 2的倍数
措施: 具体解决方法: 利用命令 sed -i 's/align 2/align 4/g' filename 替换align 2 为 align 4(align 3 替换为 align 8)
sed -i 's/align 2/align 4/g' boot/head.s
sed -i 's/align 3/align 8/g' boot/head.s
现象3: -fcombine-regs -mstring-insns选项不识别
措施: 此两个选项已经过时,直接去掉即可
现象4: warning 特别多
措施: 将-Wall 替换为 -w
现象5: __stack_chk_fail 未定义
措施: 去网上搜了一下,在Makefile中的$(CFLAGS)后面加上-fno-stack-protector,即不需要栈保护
现象6: main.c 中_syscall0重复定义
措施: main.c static inline _syscall0(int, fork) 去掉static即可
现象7: 提示内嵌汇编不符合语法限制
措施: 类似的问题在后面编译中出现好多,C内嵌汇编的格式 asm (汇编语句:输入寄存器:输出寄存器:可能被修改的寄存器),最新的GCC规定 输入或输出寄存器不能出现在可能被修改的寄存器中,目前看到网上的方法是把所有类似问题的可能被修改的寄存器全部删掉 解决方案:find -type f -exec sed -i 's/:"w{2}"(,"w{2}") )/:) /g' {} ; 其中's/:"w{2}"(,"w{2}") /:/g'
现象8: 在 control.c 中清楚定义了 static unsigned char attr = 0x70 ,而在链接 control.o 时,却爆出 attr未定义。
措施: 用 nm -C control.o 查看其符号,发现attr确实处于未定义状态。故单独编译一个小程序定义静态变量,查看其 .o 文件中,发现静态变量定义正常。故考虑为编译选项差异导致,最终发现因为 -O 编译优化选项导致,目前处理方式是去掉该选项。
现象9: build.c:(.text+0xde): undefined reference to `MAJOR'
措施: 通过分析编译打印信息,发现编译时没有加入头文件路径 -Iinclude
现象10: fs/fs.o: In function check_disk_change':(.text+0x1b2f): undefined reference to invalidate_buffers'
措施: 查找发现此函数定义在buffer.c 中,且为内联函数, 故尝试将其更改为普通函数, 然后编译通过.
现象11: 编译 build.c 时报错:/usr/include/i386-linux -gnu/bits/stdio2.h:57:8: error: unknown type name ‘__gnuc_va_list’
措施: 分析发现时此系列错误均由 -Iinclude 选项导致, 而该选项在 想象9 中加入, 故考虑去掉该选项, 直接在build.c 中加入 MAJOR 宏定义.
❾ linux内核编译问题
根据你的警告是提示,找不到这些驱动模块,应该是没有编译驱动模块或者没有安装驱动模块造成的。
1、要确保你的内核包是完整的,而且是centos配套版本(因为各大发行版都会针对自己的情况对内核进行配置和改动,直接用kernel.org的原版内核可能会有些故障)
2、编译前要 先make clean一下,把以前编译剩下的东西清掉,重头再来。
3、编译时顺序执行如下命令
make bzImage 生成内核映像
make moles 生成驱动模块
make moles_install 安装驱动模块
make install 安装内核