当前位置: 技术问答>linux和unix
交叉编译arm-linux-gcc -l参数和-L参数为什么按网友教程还是找不到.h
来源: 互联网 发布时间:2017-05-25
本文导语: 我把sqlite3.h放在.c同目录然后去掉-l才能生成,为什么没法用-l定位.h?? 网上引用.h时用的尖括号,我换成“”并且同目录能编译,不知为何 以下是网上资料: 应用程序的交叉编译: arm-softfloat-linux-gnu-gcc name.c -o ...
我把sqlite3.h放在.c同目录然后去掉-l才能生成,为什么没法用-l定位.h??
网上引用.h时用的尖括号,我换成“”并且同目录能编译,不知为何
以下是网上资料:
应用程序的交叉编译:
arm-softfloat-linux-gnu-gcc name.c -o db.out -lsqlite* -L/home/hzc/new/lib -I/home/hzc/new/include
默认的情况下,是执行动态编译,编译生成的文件比静态编译小得多,因为我们是在开发板上运行,之前已经拷贝了库文件到根文件系统里,所以这里我们采用默认的动态编译方式就行了,-lsqlite* 是指定库名,-L/home/hzc/new/lib 是指定库的搜索目录,new也就是我们刚才SQLite的安装目录,-I/home/hzc/new/include 是指定头文件的搜索目录,我们在name.c文件中头文件包含形式为 #include,还可以把头文件拷到但前name.c同目录下或者包涵时把路径也写上,这样编译时就可以不需要 –I选项了。如果没做好前面这些工作编译是通不过的,会出错误:sqlite*.h:没有这个文件或目录,提示没有找到库文件等问题。
网上引用.h时用的尖括号,我换成“”并且同目录能编译,不知为何
以下是网上资料:
应用程序的交叉编译:
arm-softfloat-linux-gnu-gcc name.c -o db.out -lsqlite* -L/home/hzc/new/lib -I/home/hzc/new/include
默认的情况下,是执行动态编译,编译生成的文件比静态编译小得多,因为我们是在开发板上运行,之前已经拷贝了库文件到根文件系统里,所以这里我们采用默认的动态编译方式就行了,-lsqlite* 是指定库名,-L/home/hzc/new/lib 是指定库的搜索目录,new也就是我们刚才SQLite的安装目录,-I/home/hzc/new/include 是指定头文件的搜索目录,我们在name.c文件中头文件包含形式为 #include,还可以把头文件拷到但前name.c同目录下或者包涵时把路径也写上,这样编译时就可以不需要 –I选项了。如果没做好前面这些工作编译是通不过的,会出错误:sqlite*.h:没有这个文件或目录,提示没有找到库文件等问题。
root@ubuntu:~/sqlite3-arm# arm-linux-gcc test.c -o test -L/home/sec/sqlite3-arm/lib -lsqlite3
test.c:3:21: error: sqlite3.h: No such file or directory
test.c: In function 'main':
test.c:23: error: 'sqlite3' undeclared (first use in this function)
test.c:23: error: (Each undeclared identifier is reported only once
test.c:23: error: for each function it appears in.)
test.c:23: error: 'db' undeclared (first use in this function)
test.c:33: warning: incompatible implicit declaration of built-in function 'exit'
test.c:45: warning: incompatible implicit declaration of built-in function 'exit'
test.c:51: error: 'SQLITE_OK' undeclared (first use in this function)
|
Is this the first time you ever compiled using gcc?
root@ubuntu:~/sqlite3-arm# arm-linux-gcc test.c -o test -L/home/sec/sqlite3-arm/lib -lsqlite3
Where is the -I/.... option on the command line?
As for the include directive:
In the C standard, section 6.10.2, paragraphs 2 to 4 state:
A preprocessing directive of the form
#include new-line
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.
A preprocessing directive of the form
#include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read
#include new-line
with the identical contained sequence (including > characters, if any) from the original directive.
root@ubuntu:~/sqlite3-arm# arm-linux-gcc test.c -o test -L/home/sec/sqlite3-arm/lib -lsqlite3
Where is the -I/.... option on the command line?
As for the include directive:
In the C standard, section 6.10.2, paragraphs 2 to 4 state:
A preprocessing directive of the form
#include new-line
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.
A preprocessing directive of the form
#include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read
#include new-line
with the identical contained sequence (including > characters, if any) from the original directive.
|
arm-linux-gcc test.c -o test -I/home/sec/sqlite3-arm/include -L/home/sec/sqlite3-arm/lib -lsqlite3