xmake-repo icon indicating copy to clipboard operation
xmake-repo copied to clipboard

Google filament, undefined reference to...

Open ArthurVasseur opened this issue 3 years ago • 20 comments
trafficstars

Xmake Version

v2.6.5+dev.34a0c28

Operating System Version and Architecture

Ubuntu 22.04 LTS

Describe Bug

Attempting to compile xmake project with google filament produce produces many undefined reference to...

Expected Behavior

Expect xmake to build the google filament package

Project Configuration

xmake.lua :

add_rules("mode.debug", "mode.release")
add_requires("filament")

target("test")
    set_kind("binary")
    add_files("main.cpp")
    add_packages("filament")
    add_links("filament")

main.cpp

#include <filament/Engine.h>
#include <filament/Camera.h>
#include <filament/Engine.h>

int main()
{
    using namespace filament;
    Engine* engine = Engine::create();
    SwapChain* swapChain = engine->createSwapChain(nullptr); // I set nullptr just for the example
    Renderer* renderer = engine->createRenderer();
}

Additional Information and Error Logs

xmake -vD

ArthurVasseur avatar May 24 '22 16:05 ArthurVasseur

https://github.com/google/filament/issues/2580

please make sure you are using clang instead of gcc. xmake f --toolchain=clang

xq114 avatar May 25 '22 11:05 xq114

I have rm .xmake and build then, xmake -f --toolchain=clang, and finally xmake, but I got the same errors xmake -vD

ArthurVasseur avatar May 25 '22 13:05 ArthurVasseur

Could you please update your xmake version to 2.6.6 and try it again? I'm wondering where did the flag -lstdc++ come from. @waruqi It should be -lc++ and -lc++abi for clang

xq114 avatar May 25 '22 14:05 xq114

For -lstdc++ I have forgot to remove it from xmake.lua, I re-run xmake and I have the same output. I have update xmake to 2.2.6, and I have the same output xmake -vD

ArthurVasseur avatar May 25 '22 15:05 ArthurVasseur

Ok, I have fix some errors, in my xmake.lua I've added add_syslinks("c++") But I've some error related to the math library I think ? https://github.com/google/filament/issues/2146 My clang version is 14, I tried with clang 11 but it gives me same errors.

xmake -vD

ArthurVasseur avatar May 26 '22 09:05 ArthurVasseur

Try to add add_syslinks("m")

SirLynix avatar May 26 '22 09:05 SirLynix

add_cxflags("-ffast-math") or add_cxflags("-fno-builtin") may help

xq114 avatar May 26 '22 09:05 xq114

I have tried your solutions, it throw me the same errors.

xmake.lua

add_rules("mode.debug", "mode.release")
add_requires("filament")

target("test")
    set_kind("binary")
    add_syslinks("c++")
    add_syslinks("m")
    add_cxflags("-fno-builtin")
    -- add_cxflags("-ffast-math") 
    set_languages("cxx17")
    add_files("main.cpp")
    add_packages("filament")
    add_links("filament")

For add_cxflags("-ffast-math") and add_cxflags("-fno-builtin") I tried both, then one, then the other, it throw me the same errors.

ArthurVasseur avatar May 26 '22 09:05 ArthurVasseur

I also tried on a fresh docker container (ubuntu:22.04), then I ran these commands :

bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
ln -s /bin/clang-14 /bin/clang
ln -s /bin/clang++-14 /bin/clang++
apt install libc++-14-dev
apt install libc++abi-14-dev
xmake

It throw me the same errors.

ArthurVasseur avatar May 26 '22 13:05 ArthurVasseur

image Why is here "-s" flag for the linker? Does it work without this flag? Currently I can't find any differences between the command line args and that recommended by filament except this flag.

xq114 avatar May 26 '22 14:05 xq114

The -s came from the add_rules("mode.release")`, I remove it and I got the same output. xmake -rvD

ArthurVasseur avatar May 26 '22 15:05 ArthurVasseur

try add_syslinks("m") in your xmake.lua

waruqi avatar May 26 '22 15:05 waruqi

I've already done that https://github.com/xmake-io/xmake-repo/issues/1239#issuecomment-1138340188

ArthurVasseur avatar May 26 '22 16:05 ArthurVasseur

try add_requires("filament", {configs = {cxflags = "-fno-builtin"}}) ?

waruqi avatar May 26 '22 16:05 waruqi

It doesn't work, same output :|

ArthurVasseur avatar May 26 '22 16:05 ArthurVasseur

or you can try shared lib first?

add_requires("filament", {configs = {shared = true}})

waruqi avatar May 26 '22 16:05 waruqi

Same output again.. xmake -rvD

ArthurVasseur avatar May 26 '22 16:05 ArthurVasseur

I think the filament package should be improved and installed using source compilation. the linux precompiled packages use clang, so the user has to be required to use clang and libc++, and there are many compiler related compatibility issues.

waruqi avatar May 27 '22 15:05 waruqi

I think the filament package should be improved and installed using source compilation. the linux precompiled packages use clang, so the user has to be required to use clang and libc++, and there are many compiler related compatibility issues.

oh, source tar.gz is too large.

waruqi avatar May 27 '22 15:05 waruqi

I think the filament package should be improved and installed using source compilation. the linux precompiled packages use clang, so the user has to be required to use clang and libc++, and there are many compiler related compatibility issues.

filament itself depends on clang and libc++, it doesn't support gcc

xq114 avatar May 28 '22 11:05 xq114

Now google has updated filament ci to build the precompiled package on Ubuntu 22.04 https://github.com/google/filament/pull/6559, so the math function issue due to glibc compatibility is gone. On the other hand, although filament need to be built with clang, the filament package only depends on libc++, which means it is also feasible to use filament with gcc now. I think this issue can finally be resolved.

xq114 avatar Mar 20 '23 16:03 xq114

So, Can I close this issue now?

waruqi avatar Mar 21 '23 01:03 waruqi