ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

c – 如何在Fedora中编译sqlite3.c?

2019-07-25 21:06:05  阅读:249  来源: 互联网

标签:c gnu makefile sqlite3


我在构建sqlite3合并时遇到了麻烦,就像我以前在windows中一样,通过将源代码编译到我的程序中,这是我当前的makefile

all:
    gcc -g -c sqlite3.c -o sqlite3.o
    g++ -g -c main.cpp -o main.o
    g++ -o test sqlite3.o main.o

我的main.cpp文件:

#include "sqlite3.h"

int main(){
  //nothing
 return 0;
}

以下是编译时收到的错误:

sqlite.o: In function `pthreadMutexAlloc':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:17910: undefined reference to
`pthread_mutexattr_init'
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:17911: undefined reference to
`pthread_mutexattr_settype'
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:17913: undefined reference to`pthread_mutexattr_destroy'
sqlite.o: In function    
`pthreadMutexTry':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:18042: undefined reference to `pthread_mutex_trylock'
sqlite.o: In function `unixDlOpen': /home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28164: undefined reference to `dlopen' 
sqlite.o: In function `unixDlError':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28178: undefined reference to `dlerror'
sqlite.o: In function `unixDlSym':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28204: undefined reference to `dlsym'
sqlite.o: In function `unixDlClose':
/home/kendal/c++/sqlite3/test/../lib/sqlite3.c:28209: undefined reference to `dlclose'

解决方法:

你还必须链接到pthreads和dl,这样做:

all:
  gcc -g -c sqlite3.c -o sqlite3.o
  g++ -g -c main.cpp -o main.o
  g++ -o test -pthread -ldl sqlite3.o main.o

使用“-lpthread”与使用“-pthread”略有不同,“ – lpthread”表示链接到pthread库,而“-pthread”表示g将为您选择带有pthread接口的相应线程库.这就是为什么你更喜欢使用“-pthread”的原因.

添加“-ldl”意味着您链接到“dl”库,该库是包含dlsym,dlopen等的库.

标签:c,gnu,makefile,sqlite3
来源: https://codeday.me/bug/20190725/1537101.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有