在ubuntu arm上编译一个简单的程序

我有一个简单的程序
#include <glib.h>
int main(){
  g_print("hallo\n");
}

并尝试使用Ubuntu在嵌入式系统(Odroid X2)上编译它

root@odroid:~/# gcc $(pkg-config --libs --cflags glib-2.0) -o main main.c
/tmp/cci48ASK.o: In function `main':
main.c:(.text+0xc): undefined reference to `g_print'
collect2: error: ld returned 1 exit status

安装的编译器:

root@odroid:~/x# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.7/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix

链接器找不到引用的任何想法?

gcc(和其他编译器)的选项顺序很重要.
gcc -Wall main.c $(pkg-config --libs --cflags glib-2.0) -o main

而且我不喜欢上述内容.您应该学习如何使用GNU make.至少,将编译标志,然后是源,然后是目标文件,然后是库(从高级到低级).

gcc -Wall $(pkg-config  --cflags glib-2.0) main.c \
    $(pkg-config --libs glib-2.0) -o main

更好的是,有一个Makefile开头

CC=gcc
CFLAGS= -Wall  $(pkg-config  --cflags glib-2.0) 
LIBES= $(pkg-config --libs glib-2.0)

应该避免以root身份编译.只有安装才需要root权限……

您可能希望添加-g(用于调试信息的编译器标志).一旦程序准备好并几乎无bug,将其替换为-O2(优化)并再次进行一些严格的测试!

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...