我正在尝试使用 liboidc-agent (Github) 这是编译的静态库。
我认为编译错误,因为当我尝试编译程序并链接库时,请参见下面的日志。
注意:/ home / gabriel / Dokumente / ...不是我的目录。但最有可能是开发人员目录。它不应该在那里,对吗?库应该是可重用的代码包。
如何解决此问题并使liboidc-agent可用? Minimal example (Github) 只需运行“ make”
还是我错过了什么? 谢谢您的帮助!
make
gcc -o main main.c -L. -I. -loidc-agent
./liboidc-agent.a(api.o): In function `oidc_serror':
/home/gabriel/Dokumente/git-repo/oidc-agent/src/oidc_error.h:95: undefined reference to `oidc_sprintf'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/oidc_error.h:97: undefined reference to `clearFreeString'
./liboidc-agent.a(api.o): In function `getAccountRequest':
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:12: undefined reference to `oidc_sprintf'
./liboidc-agent.a(api.o): In function `getAccessTokenRequest':
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:16: undefined reference to `isValid'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:19: undefined reference to `oidc_sprintf'
./liboidc-agent.a(api.o): In function `communicate':
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:27: undefined reference to `ipc_init'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:30: undefined reference to `ipc_connect'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:33: undefined reference to `ipc_vwrite'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:34: undefined reference to `ipc_read'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:35: undefined reference to `ipc_close'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:37: undefined reference to `printError'
./liboidc-agent.a(api.o): In function `getAccessToken':
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:58: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:66: undefined reference to `getJSONValues'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:67: undefined reference to `printError'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:68: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:71: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:75: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:76: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:77: undefined reference to `clearFreeString'
./liboidc-agent.a(api.o):/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:80: more undefined references to `clearFreeString' follow
./liboidc-agent.a(api.o): In function `getLoadedAccounts':
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:103: undefined reference to `getJSONValues'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:104: undefined reference to `printError'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:105: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:108: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:112: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:113: undefined reference to `clearFreeString'
/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:114: undefined reference to `clearFreeString'
./liboidc-agent.a(api.o):/home/gabriel/Dokumente/git-repo/oidc-agent/src/api.c:117: more undefined references to `clearFreeString' follow
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'main' failed
make: *** [main] Error 1
答案 0 :(得分:1)
.a
文件只是一个存档,其中包含捆绑在一起的多个.o
文件以及可选的符号索引。并且.o
文件确实引用了源文件,因此错误更精确-否则,您只会从api.o
中得到一个错误,而不是它来自的实际源文件。
真正的问题是整个 liboidc-agent.a
只是垃圾。如果您查看文件列表:
% ar t liboidc-agent.a
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
api.o
而不是几个不同的目标文件,它具有多个副本的 same 文件。与存储库所在的用户进行互动,从另一个地方获取库,或者自己从源代码构建库。
答案 1 :(得分:0)
因此,库只是已编译目标文件的集合。该库的开发人员已将其带有完整路径名的文件发送到其工作目录,该选项允许将具有相同文件名的多个目标文件保存在同一库中。
我注意到这些是头文件。 GCC始终包含include的完整路径名,因此,例如,您知道它选择了哪个setup.h文件。
如果他们简化发布过程,使路径名至少包含库名,那就更好了!