gcc链接错误

时间:2013-02-14 20:13:51

标签: linux gcc

我正在尝试构建源代码中包含的libvterm's演示。

我有这个文件夹结构:

- libvterm/
  ... // all sources are here
  - libvterm.so
  - vterm.h
  - demo/
    - vshell.c

在我做的演示目录中:

$ gcc -o vshell `pkg-config --cflags --libs glib-2.0 ncurses` vshell.c -L.. -I.. -lvterm

即使在definind -I -L 指向正确的目录后,我也会收到很多undefined reference to错误:

/tmp/ccAlNYtQ.o: In function `main':
vshell.c:(.text+0x24): undefined reference to `initscr'
vshell.c:(.text+0x29): undefined reference to `noecho'
vshell.c:(.text+0x2e): undefined reference to `start_color'
vshell.c:(.text+0x33): undefined reference to `raw'
vshell.c:(.text+0x38): undefined reference to `stdscr'
vshell.c:(.text+0x48): undefined reference to `nodelay'
vshell.c:(.text+0x4d): undefined reference to `stdscr'
vshell.c:(.text+0x5d): undefined reference to `keypad'
vshell.c:(.text+0x62): undefined reference to `stdscr'
vshell.c:(.text+0x6b): undefined reference to `stdscr'
vshell.c:(.text+0x84): undefined reference to `stdscr'
vshell.c:(.text+0x8d): undefined reference to `stdscr'
vshell.c:(.text+0xfb): undefined reference to `init_pair'
vshell.c:(.text+0x118): undefined reference to `stdscr'
vshell.c:(.text+0x121): undefined reference to `stdscr'
vshell.c:(.text+0x141): undefined reference to `stdscr'
vshell.c:(.text+0x151): undefined reference to `waddch'
vshell.c:(.text+0x176): undefined reference to `stdscr'
vshell.c:(.text+0x17e): undefined reference to `wrefresh'
vshell.c:(.text+0x1a2): undefined reference to `newwin'
vshell.c:(.text+0x1e1): undefined reference to `mvwprintw'
vshell.c:(.text+0x1ee): undefined reference to `wrefresh'
vshell.c:(.text+0x2ac): undefined reference to `wtouchln'
vshell.c:(.text+0x2b9): undefined reference to `wrefresh'
vshell.c:(.text+0x2be): undefined reference to `stdscr'
vshell.c:(.text+0x2c6): undefined reference to `wrefresh'
vshell.c:(.text+0x2d2): undefined reference to `stdscr'
vshell.c:(.text+0x2da): undefined reference to `wgetch'
vshell.c:(.text+0x308): undefined reference to `endwin'
../libvterm.so: undefined reference to `forkpty'
../libvterm.so: undefined reference to `g_free'
../libvterm.so: undefined reference to `has_colors'
../libvterm.so: undefined reference to `acs_map'
../libvterm.so: undefined reference to `wchgat'
../libvterm.so: undefined reference to `beep'
../libvterm.so: undefined reference to `pair_content'
../libvterm.so: undefined reference to `COLOR_PAIRS'
../libvterm.so: undefined reference to `g_realloc'
../libvterm.so: undefined reference to `g_malloc0'
../libvterm.so: undefined reference to `wmove'
collect2: ld returned 1 exit status

我错过了什么?

1 个答案:

答案 0 :(得分:3)

尝试重新排序您的链接命令...

gcc -o vshell vshell.c -L.. -I.. -lvterm `pkg-config --cflags --libs glib-2.0 ncurses`

在某些时候,gnu链接器更改为首先要求对象,并且库最后/更晚。