Ошибка линковки libtcc
Вознкла надобнось импортировать Tiny C Compiller в C проект. Нашел вот такой тестовый код:
#include <stdio.h>
#include <stdlib.h>
#include <libtcc.h>
void compileAndRun(const char* sourceCode) {
TCCState *tcc = tcc_new();
if (!tcc) {
printf("Error: Could not create TCC instance.\n");
return;
}
tcc_add_include_path(tcc, "C:\\tcc\\libtcc");
if (tcc_compile_string(tcc, sourceCode) == -1) {
printf("Error: Compilation failed.\n");
tcc_delete(tcc);
return;
}
if (tcc_relocate(tcc, TCC_RELOCATE_AUTO) < 0) {
printf("Error: Linking failed.\n");
tcc_delete(tcc);
return;
}
int (*mainFunc)(void) = (int (*)(void))tcc_get_symbol(tcc, "main");
if (!mainFunc) {
printf("Error: Failed to find 'main' function.\n");
tcc_delete(tcc);
return;
}
int ret = mainFunc();
tcc_delete(tcc);
printf("Program returned: %d\n", ret);
}
int main() {
const char* sourceCode =
"#include <stdio.h>\n"
"int main() {\n"
" printf(\"Hello World!\\n\");\n"
" return 0;\n"
"}\n";
compileAndRun(sourceCode);
return 0;
}
Однако нормально импортировать libtcc.h не смог, установил TCC, и пробовал скомпилировать проект с помощью: gcc -o main main.c compile.c -I"C:\tcc\include" -L"C:\tcc\lib" -ltcc
,
получаю ошибку:
In file included from C:\tcc\include/stdio.h:9,
from main.c:1:
C:\tcc\include/_mingw.h:39: warning: "__fastcall" redefined
39 | #define __fastcall __attribute__((fastcall))
|
<built-in>: note: this is the location of the previous definition
C:\tcc\include/_mingw.h:72: warning: "__stdcall" redefined
72 | #define __stdcall
|
<built-in>: note: this is the location of the previous definition
In file included from main.c:2:
C:\tcc\include/stdlib.h:139:3: error: duplicate 'extern'
139 | _CRTIMP extern int *__cdecl _errno(void);
| ^~~~~~~
main.c:3:10: fatal error: libtcc.h: No such file or directory
3 | #include <libtcc.h>
| ^~~~~~~~~~
compilation terminated.
Извините если вопрос слишком тупой, однако нигде в интернете не удалось найти информацию как правильно импортировать libtcc.h
я нашёл файл libtcc.h в tcc/libtcc однако проблему это не решило
изменил команду на такую: gcc -o main main.c -I"C:\tcc\libtcc" -L"C:\tcc\lib" -ltcc
Теперь получаю ошибку:
c:/users/lubim/gcc/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ltcc
collect2.exe: error: ld returned 1 exit status