问题描述
我对使用Makefile和autoconf非常陌生.我正在使用Camellia图片库,并尝试将我的代码静态链接到他们的库.当我在山茶花图像库上运行"make"时,在/usr/local/lib目录中得到libCamellia.a,.so,.la和.so.0.0.0文件.这是我使用其库编译代码的命令:
I'm extremely new to using Makefiles and autoconf. I'm using the Camellia image library and trying to statically link my code against their libraries. When I run "make" on the Camellia image library, I get libCamellia.a, .so, .la, and .so.0.0.0 files inside my /usr/local/lib directory. This is the command I use to compile my code with their libraries:
gcc -L/usr/local/lib -lCamellia -o myprogram myprogram.c
这很好,但是当我尝试静态链接时,这就是我得到的:
This works fine, but when I try to statically link, this is what I get:
gcc -static -L/usr/local/lib -lCamellia -o myprogram myprogram.c
/tmp/cck0pw70.o: In function `main':
myprogram.c:(.text+0x23): undefined reference to `camLoadPGM'
myprogram.c:(.text+0x55): undefined reference to `camAllocateImage'
myprogram.c:(.text+0x97): undefined reference to `camZoom2x'
myprogram.c:(.text+0x104): undefined reference to `camSavePGM'
collect2: ld returned 1 exit status
我想进行静态链接,因为我正在尝试修改山茶花的源代码,并且想将我的版本与他们的版本进行比较.因此,在进行一些谷歌搜索之后,我尝试将AM_DISABLE_SHARED添加到configure.in文件中.但是在运行./configure之后,我仍然得到完全相同的Makefile.我进行安装"后,上面的结果仍然相同.
I want to statically link because I'm trying to modify the Camellia source code and I want to compare my version against theirs. So after some googling, I tried adding AM_DISABLE_SHARED into the configure.in file. But after running ./configure, I still get the exact same Makefile. After I "make install", I still get the same results above.
获得两个版本的代码(一个带有原始的山茶花源代码,另一个带有我的修改版本)的简单方法是什么?我认为静态库应该工作.有一种简单的方法可以使静态库正常工作,或者是否有其他简单的解决方案可以解决我的问题?我只是不想每次都想将自己的版本与原始版本进行比较时重新进行"make"和"make install"操作.
What is an easy way to get two versions of my code, one with the original Camellia source code compiled and one with my modified version? I think static libraries should work. There is an easy way to get static libraries working or are there other simple solutions to my problem? I just don't want to re-"make" and re-"make install" everytime I want to compare my version against the original.
推荐答案
我不熟悉autoconf,也不知道为什么您尝试静态链接失败,但是如果动态链接有效,我认为使用共享库实际上可以解决您的问题会好一点.
I am not skillful with autoconf and I don't know why your attempt to link statically fails, but if linking dynamically works I think using shared libraries would actually solve your problem a little better.
只需建立两个共享库,一个使用原始的山茶花代码,另一个使用您的修改版本.将它们放在两个不同的目录中,然后在运行myprogram
时可以通过切换LD_LIBRARY_PATH(或用于查找库的任何东西)或在/usr/local/lib
中保留符号链接并在库之间进行切换来在它们之间进行选择.与静态库相比,此方法的优势(除了可以正常工作的事实)是,您可以修改修改后的代码,重建共享库并运行,而不必重建myprogram
(只要您不修改签名). ).
Just make two shared libraries, one with the original Camellia code and one with your modified version. Put them in two different directories, and when you run myprogram
you can choose between them either by switching LD_LIBRARY_PATH (or whatever you're using to find libraries) or by keeping a symbolic link in /usr/local/lib
and switching it between libraries. The advantage of this over static libraries (apart from the fact that this works) is that you can tinker with your modified code, rebuild the shared library and run without having to rebuild myprogram
(as long as you don't modify the signatures).
P.S.实验:尝试从/usr/local/lib
中删除共享库,并在没有-static
标志的情况下进行重建,就像使用共享库一样.从理论上讲,这应该使gcc改用静态库.结果可能为静态链接失败的原因提供线索.
P.S. An experiment: try removing the shared libraries from /usr/local/lib
and rebuilding without the -static
flag, just as if you were using the shared libraries. In theory this should cause gcc to use the static libraries instead. The results may give a clue to why the static link is failing.
这篇关于configure.in:AM_DISABLE_SHARED不会更改我的Makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!