相关疑难解决方法(0)

编译glib时链接器错误...?

我在Ubuntu上针对glib编译一个简单的示例程序时遇到了麻烦.我收到以下错误.我可以让它编译但不与-c标志链接,我相信这意味着我安装了glib标头,但它没有找到共享对象代码.另请参阅下面的Make文件.

$> make re
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include  -lglib-2.0       re.c   -o re
/tmp/ccxas1nI.o: In function `print_uppercase_words':
re.c:(.text+0x21): undefined reference to `g_regex_new'
re.c:(.text+0x41): undefined reference to `g_regex_match'
re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
re.c:(.text+0x6e): undefined reference to `g_print'
re.c:(.text+0x7a): undefined reference to `g_free'
re.c:(.text+0x8b): undefined reference to `g_match_info_next'
re.c:(.text+0x97): undefined reference to `g_match_info_matches'
re.c:(.text+0xa7): undefined reference to `g_match_info_free'
re.c:(.text+0xb3): undefined reference to `g_regex_unref'
collect2: ld returned 1 exit status
make: *** [re] Error 1
Run Code Online (Sandbox Code Playgroud)

Makefile 用过的:

# Need to …
Run Code Online (Sandbox Code Playgroud)

c linker compilation

10
推荐指数
1
解决办法
2万
查看次数

如何在使用gnu-make链接静态库时遵循链接顺序?

我有以下问题:

cc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG  build/liblcthw.a    tests/list_tests.c   -o tests/list_tests
/tmp/ccpvGjZp.o: In function `test_create':
~/lcthw/tests/list_tests.c:12: undefined reference to `List_create'
collect2: ld returned 1 exit status
make: *** [tests/list_tests] Error 1
Run Code Online (Sandbox Code Playgroud)

cc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG tests/list_tests.c  build/liblcthw.a -o tests/list_tests
Run Code Online (Sandbox Code Playgroud)

运行得很好,nm显示预期的内容,测试运行,每个人都很开心,等等.

我搜索了SO并找到了很多答案(例如链接器命令 - GCC),所以很明显链接器的工作原理应该如此.那么,我应该如何修改我的makefile以遵循命令呢?

到目前为止,这是Makefile:

CFLAGS=-g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS)
LIBS=$(OPTLIBS)
PREFIX?=/usr/local
BUILD=build

SOURCES=$(wildcard src/**/*.c src/*.c)
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))

TEST_SRC=$(wildcard tests/*_tests.c)
TESTS=$(patsubst %.c,%,$(TEST_SRC))

TARGET=$(BUILD)/liblcthw.a
TARGET_LINK=lcthw
SO_TARGET=$(patsubst %.a,%.so,$(TARGET))

#The …
Run Code Online (Sandbox Code Playgroud)

c makefile gnu-make static-linking

8
推荐指数
1
解决办法
2146
查看次数

在PintOS中运行make时获取未定义的引用"floor"

我试图在PintOS makefile上运行make,但我一直得到未定义的引用"floor"错误.makefile在下面.我用gcc 4.6.1运行Ubuntu 11.10.任何帮助表示赞赏.

    all: setitimer-helper squish-pty squish-unix
    CC = gcc
    CFLAGS = -Wall -W
    LDFLAGS = -lm
    setitimer-helper: setitimer-helper.o
    squish-pty: squish-pty.o
    squish-unix: squish-unix.o

    clean: 
          rm -f *.o setitimer-helper squish-pty squish-unix
Run Code Online (Sandbox Code Playgroud)

c gcc makefile

3
推荐指数
1
解决办法
2393
查看次数

标签 统计

c ×3

makefile ×2

compilation ×1

gcc ×1

gnu-make ×1

linker ×1

static-linking ×1