3

我正在尝试名为 .libtcc_test.c

我已经libtcc.hlibtccintoincludelibtcc.definto复制了lib
然后我跑了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'
4

2 回答 2

4

要在库中链接,您需要在所有文件或文件-l${library_basename}之后添加一个标志。如果库被命名为or (在 Windows 上可能是or ),您需要添加.colibtcc.alibtcc.sotcc.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 repo 中的 from 还需要库libtcc_test.c(用于动态加载的标准库)来构建:test/libtcc_test.cdl

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

(它抱怨 undefined dlopen, dlclose, 和dlsym已知来自libdl)。

于 2017-04-01T10:40:40.077 回答
1

以下命令适用于 Windows:

cd your-tcc-directory
tcc -Ilibtcc -L. -ltcc examples/libtcc_test.c

您可能想要添加-run以跳过生成 exe 文件并直接运行源代码。

我在 Linux 上尝试过,但找不到libtcc.h. 我想以下方法会起作用(注意-ltcc1而不是-ltcc):

tcc -I/path/to/libtcc.h/location -L/usr/lib/tcc/x86-64 -ltcc1 path/to/libtcc_test.c
于 2017-07-05T00:38:14.737 回答