I have a relatively simple c project from the Torizon Ide Extension CMAKE template in vscode.
I would like to either add a precompiled *.a library, or insert it directly into the project, compile it and link it to the main application.
(e.g. an asn1 lib)
I now need to know and understand how to get this lib into the container.
I suspect by editing the Dockerfile files.
For example, let’s say I have a libAsn1Scheme.a file and want to make it available to my main application.
I store the corresponding headers under asn1/include.
Where do I store the libAsn1Scheme.a and what changes do I have to make where?
Or is there a ready working example?
Generally speaking, if you want to add any file to a container you can include it when building the container image by using the ADD instruction in the Dockerfile:
However, I believe the CMake template from the extension already adds the entire project directory to the SDK container when building the application, so adding the .a file in the project directory should be enough.
Of course, you still need to adapt your CMakeLists.txt to use it during the compilation/linking process.
[ 50%] Linking C executable debug/RpmsgTtyTester
/usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /app/HDLCSchemeAsn1.a(der_encoder.o): Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /app/HDLCSchemeAsn1.a(der_encoder.o): Relocations in generic ELF (EM: 62)
/usr/lib/gcc-cross/aarch64-linux-gnu/12/../../../../aarch64-linux-gnu/bin/ld: /app/HDLCSchemeAsn1.a: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/RpmsgTtyTester.dir/build.make:98: debug/RpmsgTtyTester] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:100: CMakeFiles/RpmsgTtyTester.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
I find it strange that the program works ‘locally’ without any problems and in the arm64 version I get this error message. (error adding symbols: file in wrong format)
The error message can mean that you’re trying to link a library that was compiled for a different architecture than what the cross-compiler generates e.g. trying to link a amd64/x86_64 library when the compiler generates aarch64 binaries.
If that’s the case then it would make sense that it works when building for your local machine, but it doesn’t when trying to build for arm64.
For which architecture was your static library .a file compiled?