如何修复从源代码构建TinyCCompiler(TCC)时crt1.o和crti.o错误的问题?

7

如何修复在编译TinyCCompiler(TCC)源代码时出现crt1.o和crti.o错误?

https://github.com/LuaDist/tcc

我在我的桌面系统(Ubuntu)上测试了它,并在服务器(CentOS)上进行了测试。在两种操作系统中都显示错误。

错误信息:

tcc: file '/usr/lib/crt1.o' not found
tcc: file '/usr/lib/crti.o' not found

详情:

guest@Base:~/Gits/tcc-compiler$ ./configure --prefix=build

这行命令是在Linux系统中运行的。它将配置一个tcc编译器,并将其安装在名为“build”的目录中。
Binary  directory   build/bin
TinyCC directory    build/lib/tcc
Library directory   build/lib
Include directory   build/include
Manual directory    build/man
Doc directory       build/share/doc/tcc
Target root prefix  
Source path      /home/guest/Gits/tcc-compiler
C compiler       gcc
CPU              x86-64
Big Endian       no
gprof enabled    no
cross compilers  no
use libgcc       no
Creating config.mak and config.h
config.h is unchanged

guest@Base:~/Gits/tcc-compiler$ sudo make

....
....

guest@Base:~/Gits/tcc-compiler$ sudo make install

mkdir -p "build/bin"
install -s -m755 tcc "build/bin"
mkdir -p "build/man/man1"
install tcc.1 "build/man/man1"
mkdir -p "build/lib/tcc"
mkdir -p "build/lib/tcc/include"
install -m644 libtcc1.a "build/lib/tcc"
install -m644 include/stdarg.h include/stddef.h include/stdbool.h include/float.h include/varargs.h include/tcclib.h "build/lib/tcc/include"
mkdir -p "build/share/doc/tcc"
install -m644 tcc-doc.html "build/share/doc/tcc"
mkdir -p "build/lib"
install -m644 libtcc.a "build/lib"
mkdir -p "build/include"
install -m644 libtcc.h "build/include"

guest@Base:~/Gits/tcc-compiler$ cat test2.c

#include <tcclib.h>

int main()
{
    printf("Hello World\n");
    return 0;
}

错误:

guest@Base:~/Gits/tcc-compiler$ build/bin/tcc test2.c

这段文本是关于在终端中使用tcc编译器编译test2.c文件时出现的错误。
tcc: file '/usr/lib/crt1.o' not found
tcc: file '/usr/lib/crti.o' not found

$ find /usr/ -name crti*

/usr/mipsel-linux-gnu/lib/crti.o
/usr/lib32/crti.o
/usr/libx32/crti.o
/usr/lib/i386-linux-gnu/crti.o
/usr/lib/x86_64-linux-gnu/crti.o

$ find /usr/ -name crt1*

/usr/mipsel-linux-gnu/lib/crt1.o
/usr/lib32/crt1.o
/usr/libx32/crt1.o
/usr/x86_64-w64-mingw32/lib/crt1.o
/usr/x86_64-w64-mingw32/lib/crt1u.o
/usr/i686-w64-mingw32/lib/crt1.o
/usr/i686-w64-mingw32/lib/crt1u.o
/usr/lib/i386-linux-gnu/crt1.o
/usr/lib/x86_64-linux-gnu/crt1.o

完整命令请参见https://pastebin.ubuntu.com/26211506/

如何修复错误?


我可以使用sudo apt install tcc安装tcc。(没有错误和bug)

但我想从源代码安装tcc。(这里出现了错误)


新更新

tcc.h文件中:

#define CONFIG_TCC_CRT_PREFIX CONFIG_SYSROOT "/usr/lib"

我将 /usr/lib 更改为 /usr/lib/x86_64-linux-gnu

$ build/bin/tcc test.c -run

Hello World

$ /build/bin/tcc test.c

tcc: undefined symbol '__libc_csu_fini'
tcc: undefined symbol '__libc_csu_init'
tcc: undefined symbol '__libc_start_main'
tcc: undefined symbol 'printf'

新更新

#include <tcclib.h>
int main()
{
    printf("Hello World\n");
    return 0;
}

guest@Base:~/Gits/tcc-try/_build/_install/bin$ ./tcc test.c

这是一个命令行指令,用于运行名为“tcc”的程序,同时将“test.c”文件作为输入传递给该程序。
test.c:1: include file 'tcclib.h' not found

如何解决包含文件未找到的错误?!

相关问题: 如何在TinyCCompiler(TCC)中解决包含文件错误?


2
这似乎是你应该向你正在尝试构建的程序的维护者询问的内容。 - Christian Gibbons
我无法访问它们。在stackoverflow上有可用的“tcc”标签。@ChristianGibbons - C-Compiler
2
仅仅因为我们有一个[tcc]标签,并不意味着所有关于tcc的问题都适合在这里讨论。抱歉。但是你有一个源代码分发包,很可能其中包含了如何联系维护者的信息。 - John Bollinger
1
就我看来,这似乎是一个配置/安装问题。 - John Bollinger
你也没有安装吗?@JohnBollinger - C-Compiler
显示剩余4条评论
2个回答

1
LuaDist项目旨在使用CMake构建完整的Lua生态系统。因此,您应该使用CMake构建系统而不是原始的makefiles。通常,您需要执行以下CMake调用。
$ mkdir _build && cd _build
$ cmake .. -DCMAKE_INSTALL_PREFIX=_install
$ cmake --build . --target install

在此之后,您应该在_install/bin中拥有可工作的tcc。

`#include <stdlib.h> #include <stdio.h>int main() { printf("Hello World\n"); return 0; }, $ ./tcc ../test.c ../test.c:1: include file 'stdlib.h' not found` - C-Compiler
#include <tcclib.h>int main() { printf("你好,世界\n"); return 0; }$ ./tcc ../test.c../test.c:1: 找不到包含文件 'tcclib.h' - C-Compiler
如何解决include文件找不到的错误?!@drahosp - C-Compiler
@C编译器:停止洪水般的提问。对于你的问题,简明扼要地表达一次就足够了。如果回答者想看更多细节,他会自己去查看的。但不要强求。 - Tsyvarev
好的,抱歉,但我需要一个小型的C编译器。@Tsyvarev - C-Compiler

1

抱歉,这不是针对问题的确切答案,但最初我有同样的问题,这是我的解决方案(Ubuntu 18.04):

git clone https://github.com/TinyCC/tinycc
cd tinycc
./configure
make
make test
cd ..
echo '#include <stdio.h>
int main() {
 printf("Hi!\n");
}' > a.c
tinycc/tcc -Btinycc a.c -o a.o
./a.o

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接