0

I'm trying to statically link glib into my C program. I'm not sure what's the best way to do this. I downloaded the code and put it in a subdirectory called glib-2.36.4. I added "-Iglib-2.36.4" when using gcc. The glib.h is in the glib-2.36.4/glib directory and in that file there are references to other header files under the glib directory (such as #include ).

I'm not sure why that is since both glib.h and these other header files are at the same level (in glib subdirectory). I got a compile error due to galloca.h not being found (even though it's there). So I copied glib.h up one level and those errors went away. I then got an error about a missing glibconfig.h. I copied that from my usr directory and that error went away. I compiled my project and now I'm getting an error about undefined reference to g_ptr_array_new. I guess this must be because I haven't actually compiled glib. I had tried to build glib, but when I typed "./configure", but I got this message:

checking if arpa/nameser_compat.h is needed... configure: error: could not compile test program either way

I did install glib using yum, but I really want this code to run even if glib is not installed on a machine.

4

1 回答 1

1

您需要通过 yum安装 glib 和glib-dev ,使用 ./configure 进行编译, (查看 ./configure 脚本以查看是否需要提供任何标志或定义您需要生成静态构建)无需移动任何文件,然后您需要使用 -i path/to/glib/includes 编译代码并与 -L path/to/built/static/library 链接

于 2013-09-09T07:31:45.073 回答