@giuliomoro oh yeah, good point. Maybe the submodule URL is using a different protocol than the main repo. Thanks!
cross compilation for bela
I am just starting out with Bela and am trying to setup my development environment. I was following this guide: https://github.com/BelaPlatform/Bela/wiki/Compiling-Bela-projects-in-Eclipse but ran into the issue where libmathneon is not available on my system.
So is using xcBela - or the mentioned docker container - the prefered way to go? Does this deprecate this wiki page then?
xcBela
or the docker container are probably better options if you are familiar with the terminal and you don't need to use Eclipse.
If you want to use Eclipse, there are probably a couple of amendments to be made there. One, here, requires some extra files to be copied (on top of the one mentioned at that link, we are now also reading /usr/include/linux/version.h
) and possibly needs to modify the paths. Ultimately, if you copy the whole content of the board, it shouldn't be a problem.
Well, things were working great until I tried to use something from AudioFile
. I'm getting link errors.
compile command:
/usr/local/opt/llvm/bin/clang++ --target=arm-linux-gnueabihf --sysroot=<host-machine>/xcBela/sysroot -isysroot <host-machine>/xcBela/sysroot -isystem <host-machine>/xcBela/sysroot/usr/include/c++/6.3.0 -isystem <host-machine>/xcBela/sysroot/usr/include/arm-linux-gnueabihf/c++/6.3.0 -L<host-machine>/xcBela/sysroot/usr/lib/gcc/arm-linux-gnueabihf/6.3.0 -B<host-machine>/xcBela/sysroot/usr/lib/gcc/arm-linux-gnueabihf/6.3.0 --gcc-toolchain=TOOLCHAIN/arm-linux-gnueabihf-binutils -I<host-machine>/xcBela/sysroot/root/Bela -I<host-machine>/xcBela/sysroot/root/Bela/include -I<host-machine>/xcBela/sysroot/usr/xenomai/include <host-machine>/xcBela/Bela/Core/default_main.cpp render.cpp -Wl,--no-as-needed -L<host-machine>/xcBela/sysroot/usr/local/lib -L<host-machine>/xcBela/sysroot/usr/xenomai/lib -L<host-machine>/xcBela/sysroot/root/Bela/lib -lcobalt -lmodechk -lpthread -lrt -lprussdrv -lstdc++ -lasound -lseasocks -lNE10 -lmathneon -ldl -latomic -l:libbelafull.a -o play-file
error:
/usr/local/bin/arm-linux-gnueabihf-ld: <host-machine>/xcBela/sysroot/root/Bela/lib/libbelafull.a(AudioFileUtilities.o): in function `AudioFileUtilities::getSamples(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float*, unsigned int, unsigned int, unsigned int)':
/root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:14: undefined reference to `sf_open'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:15: undefined reference to `sf_strerror'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:16: undefined reference to `sf_close'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:36: undefined reference to `sf_seek'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:39: undefined reference to `sf_read_float'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:48: undefined reference to `sf_close'
/usr/local/bin/arm-linux-gnueabihf-ld: <host-machine>/xcBela/sysroot/root/Bela/lib/libbelafull.a(AudioFileUtilities.o): in function `AudioFileUtilities::getNumChannels(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:57: undefined reference to `sf_open'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:61: undefined reference to `sf_close'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:58: undefined reference to `sf_strerror'
/usr/local/bin/arm-linux-gnueabihf-ld: <host-machine>/xcBela/sysroot/root/Bela/lib/libbelafull.a(AudioFileUtilities.o): in function `AudioFileUtilities::getNumFrames(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:70: undefined reference to `sf_open'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:74: undefined reference to `sf_close'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:71: undefined reference to `sf_strerror'
/usr/local/bin/arm-linux-gnueabihf-ld: <host-machine>/xcBela/sysroot/root/Bela/lib/libbelafull.a(AudioFileUtilities.o): in function `AudioFileUtilities::write(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float*, unsigned int, unsigned int, unsigned int)':
/root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:86: undefined reference to `sf_open'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:93: undefined reference to `sf_writef_float'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:96: undefined reference to `sf_close'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:103: undefined reference to `sf_strerror'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:89: undefined reference to `sf_close'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:90: undefined reference to `sf_strerror'
/usr/local/bin/arm-linux-gnueabihf-ld: /root/Bela/libraries/AudioFile/AudioFileUtilities.cpp:97: undefined reference to `sf_strerror'
Looks like the linker isn't finding libsndfile.XXX
which only exists in xcBela/sysroot/usr/lib/arm-linux-gnueabihf/libsndfile.XXX
, at least on my system.
Nope, that means that the linker is not looking for it. On Bela, libraries can require compiler or linker flags to be added. This is a fairly elaborated complicated mechanism that involves resources/tools/detectlibraries.sh
, which in turn generates a number of intermediate makefiles that are included as appropriate by the main Makefile
and/or Makefile.link
. Additionally, Makefile.libraries
takes care of building the libraries themselves. All of this is so that when a user includes libraries/AudioFile/AudioFile.h
, the latter's implementation is linked in and the fact that the latter's implementation depends on libsndfile
is transparent to the user, as the lib.metadata files requires it for them.
All of the above is for regular users, who use the Bela Makefile
. xcBela
does not do that, but that's for experienced users like you: so as an advanced user you can figure out what libraries you need and them in. It would seem that xcCompile
will pass to clang++
any LDFLAGS
you may have set in your environment.
So
LDFLAGS=-lsndfile xcCompile whatev
or
export LDFLAGS=-lsndfile # only needs to do this once
xcCompile whatev # run this without need to specify the above again
should tell clang++
to look for libsndfile
.
That should hopefully fix it?
Note: @thetechnobear an alternative way to deal with this is for libbelafull.so
to be linked against any shared libraries that are required (just grep
for LDFLAGS=
and LDLIBS=
in all the libraries/*/lib.metadata
). Then tell the linker not to complain about unresolved symbols in the dependencies and you'll be back to the point where libbelafull
is all you need (hopefully!).
@giuliomoro Wow, thanks for the rapid delivery. Do you ever take time off? :-)
Excellent, that did it. Playing WAV files on Bela now.
In the end I had to add:
-lsndfile -lFLAC -logg -lvorbis -lvorbisenc
At some point I'll work out the most scalable way to weave these kind of mods into my xcBela
toolchain, but for now I'm ready to move onto the next phase of development.
Once again, thanks so much.
- Edited
sorry, been busy on other projects....
not really followed the above... but indeed Ive been setting things like LDFLAGS if I needed something 'extra'.
I didn't really think too much about it since many of my projects require this anyway
(e.g. Ive other projects, which basically use xcBela as a kind of a starting point, so their builds add to the environment)
giuliomoro Note: @thetechnobear an alternative way to deal with this is for libbelafull.so to be linked against any shared libraries that are required (just grep for LDFLAGS= and LDLIBS= in all the libraries/*/lib.metadata). Then tell the linker not to complain about unresolved symbols in the dependencies and you'll be back to the point where libbelafull is all you need (hopefully!).
interesting, sure this would work for libs that are within the bela libraries
I need to review some of this, I know you were making some changes around the libbelafull area, and I cant remember if i reflected this in xcBela in the end. (as you say, at some point id made some changes locally to 'make it work')
Thank you so much for making this @thetechnobear !!
It has helped me a lot to get my projects moving !!
I converted the xcCompile script into a makefile such that all the .o and .d files are built before being linked into a program. This makes the build incremental. It also enables multicore support with -j flag...
My Bela projects currently takes about 40 min for clean build on the Bela (BBB), 5 minutes with distcc and 20 seconds with cross-compilation on 8 threads....
Great help !
Thanks a 1000000
giuliomoro
Hei, I'm just trying to make this work. The same problem appeared that @willismorse described earlier. The XC_ROOT/sysroot/root/ folder doesn't exist but the install.sh worked fine without any errors.
So I tried your solution @giuliomoro by adding those two files to the bela board and reran install_bela.sh.
First of all: Is this what you meant in your post? After running I get a lot of "first defined here" errors, I copy the last few lines below.
It would be so nice to make this work. Any solutions to this would be really nice!
Thanks
/root/Bela/libraries/WSServer/WSServer.cpp:13: multiple definition of
WSServer::WSServer()'
build/core/WSServer.o:/root/Bela/core/WSServer.cpp:13: first defined here
libraries/WSServer/build/WSServer.o: In function ~WSServer':
WSServer::WSServer()'
/root/Bela/libraries/WSServer/WSServer.cpp:13: multiple definition of
build/core/WSServer.o:/root/Bela/core/WSServer.cpp:13: first defined here
clang: error: linker command failed with exit code 1 (use -v to see invocation)
CustomMakefileBottom.in:6: recipe for target 'lib/libbelafull.so' failed
make: *** [lib/libbelafull.so] Error 1`
Can you clearly detail what code you are using and what steps you've taken? I'd rather not have to try to piece that together from a 4 year old conversation.
Hei in the meantime i tried to configure distcc and it works fine. Compiling time is much faster than before I’m happy with that for now.
Concerning xcBela I just tried to follow the steps in the tutorial and came pretty far with that. I only had to change some file paths. But I can’t remember exactly what I did. I have to commit I used a lot of ChatGPT to figure out what’s going on. Sorry for my insufficient answer. I’m self taught in all this and I always find myself jumping from question mark to question mark. but thanks for answering so quickly!!