gpt4 book ai didi

C 链接错误(使用 tcc)

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:27 27 4
gpt4 key购买 nike

我正在尝试运行来自 tiny cc 的示例(tcc-0.9.26-win64-bin.zip) 调用了 libtcc_test.c

我已经将 libtcc.hlibtcc 复制到 include 并将 libtcc.def 复制到 .
然后我运行 tcc ./examples/libtcc_test.c 并得到一个链接错误:/

tcc: error: undefined symbol 'tcc_new'
tcc: error: undefined symbol 'tcc_set_lib_path'
tcc: error: undefined symbol 'tcc_set_output_type'
tcc: error: undefined symbol 'tcc_compile_string'
tcc: error: undefined symbol 'tcc_add_symbol'
tcc: error: undefined symbol 'tcc_relocate'
tcc: error: undefined symbol 'tcc_get_symbol'
tcc: error: undefined symbol 'tcc_delete'

我错过了什么?


更多信息:

P:\cpp\tcc>tcc ./examples/libtcc_test.c -vv
tcc version 0.9.26 (i386 Win32)
-> ./examples/libtcc_test.c
-> p:/cpp/tcc/include/stdlib.h
-> p:/cpp/tcc/include/_mingw.h
-> p:/cpp/tcc/include/stddef.h
-> p:/cpp/tcc/include/stdarg.h
-> p:/cpp/tcc/include/limits.h
-> p:/cpp/tcc/include/sec_api/stdlib_s.h
-> p:/cpp/tcc/include/stdlib.h
-> p:/cpp/tcc/include/malloc.h
-> p:/cpp/tcc/include/stdio.h
-> p:/cpp/tcc/include/vadefs.h
-> p:/cpp/tcc/include/sec_api/stdio_s.h
-> p:/cpp/tcc/include/stdio.h
-> p:/cpp/tcc/include/string.h
-> p:/cpp/tcc/include/sec_api/string_s.h
-> p:/cpp/tcc/include/string.h
-> p:/cpp/tcc/include/libtcc.h
-> p:/cpp/tcc/lib/libtcc1.a
-> p:/cpp/tcc/lib/msvcrt.def
-> p:/cpp/tcc/lib/kernel32.def
tcc: error: undefined symbol 'tcc_new'
tcc: error: undefined symbol 'tcc_set_lib_path'
tcc: error: undefined symbol 'tcc_set_output_type'
tcc: error: undefined symbol 'tcc_compile_string'
tcc: error: undefined symbol 'tcc_add_symbol'
tcc: error: undefined symbol 'tcc_relocate'
tcc: error: undefined symbol 'tcc_get_symbol'
tcc: error: undefined symbol 'tcc_delete'

最佳答案

要在库中链接,您需要在所有c 文件或o 文件之后添加一个-l${library_basename} 标志。如果库名为 libtcc.alibtcc.so(在 Windows 上它可能是 tcc.dlllibtcc.dll),需要添加-ltcc

tcc  ./examples/libtcc_test.c  -ltcc

您可能还需要添加一个 -L 标志来添加搜索路径,以防您要链接的库不是您系统的标准库目录:

tcc -L . ./examples/libtcc_test.c -ltcc
#also look for libtcc.so or libtcc.a in the current directory (.)

tinycc 仓库中 test/libtcc_test.c 中的 libtcc_test.c 还需要 dl 库(动态加载的标准库)构建:

tcc -L .  tests/libtcc_test.c  -ltcc -ldl #worked 

(它提示未定义的 dlopendlclosedlsym,它们已知来自 libdl) .

关于C 链接错误(使用 tcc),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43155517/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com