taisei-project / taisei

A free and open-source Touhou Project fangame
https://taisei-project.org/
Other
1.12k stars 97 forks source link

Linking fails with "undefined symbol: main" #322

Closed HybridDog closed 3 years ago

HybridDog commented 3 years ago

I tried to build the latest version (85e3cf0) by following the instructions. I think the linker cannot find the main function. Here's an excerpt of the messages show by ninja:

[2/2] Linking target src/taisei
FAILED: src/taisei 
c++  -o src/taisei src/taisei.p/meson-generated_.._version_auto.c.o […] 
ld.lld: error: undefined symbol: main
>>> referenced by init.c
>>>               /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../../lib/Scrt1.o:(_start)

Here's the full output: ninja_output.txt

Compiler: gcc 11 (wrapped by ccache) Linker: lld 12 (using a symbolic link from ~/bin/ld to /usr/bin/ld.lld)

StarWitch commented 3 years ago

Thank you for the report. I just tried to compile using clang (on macOS) and things worked correctly.

Could you try running the following commands to see if it fixes the problem for you? This is assuming you're in the base taisei/ directory.

cd taisei/
rm -r build/
git submodules update --recursive --init
meson setup -C build/
meson compile -C build/

Let me know if that ends up working for you. I'm also currently working on better documentation for building, which you can check out in #319.

Akaricchi commented 3 years ago

Compiler: gcc 11 Linker: lld 12

I think this might be the problem here, combined with Taisei's LTO-by-default setting. lld probably does not understand gcc's LTO object format, so it fails to link anything into the binary. I would not recommend using lld and gcc together, and especially wouldn't recommend overriding your system's default linker like that (if you must, you can tell the compiler which linker to use via -fuse-ld=lld). To test this hypothesis, try disabling LTO via meson configure -Db_lto=false and recompiling. That should give you a working build with gcc+lld, albeit less optimized. If that works, I would recommend enabling LTO back and either using the gold linker with gcc (meson configure -Dcpp_link_args="-fuse-ld=gold"), or using clang if you want to use lld.

HybridDog commented 3 years ago

Thanks for the help. Changing the linker indeed fixed the problem; there is an related issue at llvm.org: Bug 42446.