open62541 library build on Windows differents with release files - cmake

I trying to go into the open62541 project to use it in my solution. My platform is windows.
At first, I downloaded the release files (open62541.h/c) and compiled the server example with GCC compiler (MinGW64).
$ gcc -std=c99 open62541.c myServer.c -l"ws2_32" -o myServer
That works. So my following step was to get the newest master from GitHub, and build it with CMAKE. I used the following CMAKE configuration:
CMAKE configuration
UA_NAMESPACE_ZERO Reduced is used due to FULL will cause CAMKE to fail generate project:
CMake Error at CMakeLists.txt:1156 (message):
File
C:/Users/lukasz/Desktop/open62541-visual/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
not found. You probably need to initialize the git submodule for
deps/ua-nodeset or set open62541_NODESET_DIR.
That will create a .sln, and simple build all creates open62541.h/c. When I try to compile the example with generated files I got this error:
> $ gcc -std=c99 open62541.c myServer.c -l"ws2_32" -o myServer
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
> C:\msys64\tmp\ccs27GQ8.o:myServer.c:(.text+0xa3): undefined reference
> to `__imp_UA_ServerConfig_setMinimalCustomBuffer'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
> C:\msys64\tmp\ccs27GQ8.o:myServer.c:(.text+0xe3): undefined reference
> to `__imp_UA_Log_Stdout'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
> C:\msys64\tmp\ccs27GQ8.o:myServer.c:(.text+0x13e): undefined reference
> to `__imp_UA_Server_new'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
> C:\msys64\tmp\ccs27GQ8.o:myServer.c:(.text+0x152): undefined reference
> to `__imp_UA_Server_getConfig'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
> C:\msys64\tmp\ccs27GQ8.o:myServer.c:(.text+0x171): undefined reference
> to `__imp_UA_Server_run'
> C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
> C:\msys64\tmp\ccs27GQ8.o:myServer.c:(.text+0x184): undefined reference
> to `__imp_UA_Server_delete' collect2.exe: error: ld returned 1 exit
> status
What causes that difference to released files?

Related

CMAKE_EXE_LINKER_FLAGS vs target_link_libraries

trying to play around with odas library, using following CMakeLists.txt file to crosscompile for Raspberry PI platform:
make_minimum_required(VERSION 3.10)
# Set some basic project attributes
project (Audio_Sweep_Cross_CMake_04
VERSION 0.1
DESCRIPTION "Audio Sweep Project")
# Referencing ODAS here
include (CMakeListsOdas.cmake)
#Add base directory for includes (global)
include_directories(include)
set (SRC src)
# This project will output an executable file
add_executable(${PROJECT_NAME} ${SRC}/main.cpp )
# Include the configuration header in the build
SET(GCC_COVERAGE_LINK_FLAGS "-lm -lpthread " )
set(ENV{PKG_CONFIG_PATH} "/sysroot/usr/lib/aarch64-linux-gnu/pkgconfig")
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_ALSA REQUIRED alsa)
pkg_check_modules(PC_FFTW3 REQUIRED fftw3f)
pkg_check_modules(PC_LIBCONFIG REQUIRED libconfig)
pkg_check_modules(PC_PULSEAUDIO REQUIRED libpulse-simple)
target_link_libraries(${PROJECT_NAME}
odas
${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
${PC_PULSEAUDIO_LIBRARIES}
# m
# pthread
)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
This one compiles no problem.
However, if I comment out
# SET(GCC_COVERAGE_LINK_FLAGS "-lm -lpthread " )
and un-comment m and pthread in
target_link_libraries(${PROJECT_NAME}
odas
${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
${PC_PULSEAUDIO_LIBRARIES}
m
pthread
)
then, when i try to build the project, i am getting a bunch of errors:
**** Incremental Build of configuration Debug for project RPI_audio_sweep_04 ****
/usr/bin/ninja -j 8 all
[1/1] Linking CXX executable Audio_Sweep_Cross_CMake_04
FAILED: Audio_Sweep_Cross_CMake_04
: && /opt/x-tools/aarch64-rpi3-linux-gnu/bin/aarch64-rpi3-linux-gnu-g++ --sysroot=/sysroot -g --sysroot=/sysroot CMakeFiles/Audio_Sweep_Cross_CMake_04.dir/src/main.cpp.o -o Audio_Sweep_Cross_CMake_04 -Wl,-rpath,/RPI_audio_sweep_04/_build/Debug libodas.so -lfftw3f -lasound -lconfig -lpulse-simple -lpulse -lm -lpthread && :
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(pthread_create.o): in function `allocate_stack':
./nptl/allocatestack.c:525: undefined reference to `_dl_stack_flags'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/allocatestack.c:647: undefined reference to `_dl_stack_flags'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_initialize_minimal_internal':
./nptl/nptl-init.c:335: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:344: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:360: undefined reference to `_dl_init_static_tls'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: ./nptl/nptl-init.c:362: undefined reference to `_dl_wait_lookup_done'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(nptl-init.o): in function `__pthread_get_minstack':
./nptl/nptl-init.c:393: undefined reference to `_dl_pagesize'
/opt/x-tools/aarch64-rpi3-linux-gnu/bin/../lib/gcc/aarch64-rpi3-linux-gnu/12.2.0/../../../../aarch64-rpi3-linux-gnu/bin/ld.bfd: /sysroot/lib/aarch64-linux-gnu/libpthread.a(unwind.o): in function `_jmpbuf_sp':
./nptl/../sysdeps/aarch64/jmpbuf-offsets.h:52: undefined reference to `__pointer_chk_guard_local'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
"/usr/bin/ninja -j 8 all" terminated with exit code 1. Build might be incomplete.
Not sure what is going on here.

How to solve cmake linking error `lld: error: undefined symbol: llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool) ...`

I am trying to compile from source ypsilon, but couldn't get it installed on Ubunut 22.04 LTS after multiple trial-and-errors.
I followed the official instructions linked above but process fails at cmake --build ., complaining that it couldn't find llvm. Then, I used cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake .... Now, the compilation is OK, but there are many link errors even after trying out -DCMAKE_EXE_LINKER_FLAGS_RELEASE=:
$ cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake -DCMAKE_EXE_LINKER_FLAGS_RELEASE=-L/usr/lib/llvm-14/lib -DCMAKE_BUILD_TYPE=Release .. && cmake --build . |& tee ~/a.txt
-- Build type: Release
-- Found LLVM 14.0.0
-- Using LLVMConfig.cmake in: /usr/lib/llvm-14/cmake
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/tmp/ypsilon/build
[ 2%] Building CXX object CMakeFiles/ypsilon.dir/src/arith.cpp.o
...
[100%] Linking CXX executable ypsilon
ld.lld: error: undefined symbol: llvm::Type::getInt32Ty(llvm::LLVMContext&)
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<8>::copy(llvm::Value*))
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<24>::copy(llvm::Value*))
>>> referenced by ld-temp.o
>>> lto.tmp:(digamma_t::reg_cache_t<16>::copy(llvm::Value*))
>>> referenced 96 more times
ld.lld: error: undefined symbol: llvm::ConstantInt::get(llvm::IntegerType*, unsigned long, bool)
...
ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [CMakeFiles/ypsilon.dir/build.make:817: ypsilon] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:164: CMakeFiles/ypsilon.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
I am not familiar with cmake or its linking flags on the command line.
Does any one know how to fix the cmake linking issue in the above commands?
The steps I tried are as follows:
sudo apt install clang lld
git clone https://github.com/fujita-y/ypsilon.git
cd ypsilon/ ; mkdir -p build ; cd build
cmake -DLLVM_DIR=/usr/lib/llvm-14/cmake -DCMAKE_EXE_LINKER_FLAGS_RELEASE=-L/usr/lib/llvm-14/lib -DCMAKE_BUILD_TYPE=Release .. && cmake --build .

undefined reference error when trying to build gprc

I tried to build grcp with CMake on Linux, but running into some errors.
Log report
/usr/bin/ld: libgrpc++_test_config.so.1.31.0:undefined reference to 'google::ParseCommandLineFlags(int*, char***, bool)'
I've already installed gflags and gflags-devel package and I tried
ldd libgrpc++_test_config.so.1.31.0
but there is no link to gflags...
I think the cmake/gflags.cmake has some error in line 28 because find_package target is gflags but the next line TARGET become gflags:: gflags...
This is my build command:
cmake ../.. -DgRPC_INSTALL=ON -DCMAKE_BUILD_TYPE=Release -DgRPC_CARES_PROVIDER=package -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DgRPC_ZLIB_PROVIDER=package -DgRPC_GFLAGS_PROVIDER=package -DgRPC_BUILD_TESTS=ON -DBUILD_SHARED_LIBS=ON
make
make install

How to include mruby after installing with rbenv/ruby-build?

I'm trying to compile the "Source Code (.c)" example from this tutorial.
I have installed mruby using rbenv: rbenv install mruby-1.2.0
I get an error when trying to compile the program:
$ gcc -std=c99 -Imruby/include test_program.c -o test_program
test_program.c:1:10: fatal error: 'mruby.h' file not found
#include "mruby.h"
^
1 error generated.
How am I supposed to reference the mruby library when installing via rbenv/ruby-build?
Seems like rbenv install mruby-1.2.0 doesn't install header files of mruby(it's only a dump of build/host directory after mruby is built):
% ls $(rbenv prefix mruby-1.2.0)
LEGAL bin lib mrbgems mrblib src
You need
# get mruby's code
git clone https://github.com/mruby/mruby.git mruby
# build mruby
cd mruby && rake
# go back to directory of `test_program.c`
cd ..
before test_program.c's compilation instead.
And you need mruby/build/host/lib/libmruby.a -lm compile options too.
add -lm
in mruby is /include directory in my source is possible -I mruby_directory/include
next add ~/mruby/build/host/lib/libmruby.a

CMake, SDL on Mac OS X, "can't find -lSDLmain"

Following the instructions here, I've set up a CMakeLists.txt:
Find_Package (SDL REQUIRED)
Find_Package (SDL_image REQUIRED)
link_libraries (
${SDL_LIBRARY}
${SDLIMAGE_LIBRARY}
SDLmain
)
When running cmake, I get the following error:
ld: library not found for -lSDLmain
collect2: error: ld returned 1 exit status
make[2]: *** [src/GameOfLife] Error 1
Running g++ by hand gives the same error:
$ g++-4.7 -std=c++0x ../src/*.cpp -lSDLmain
ld: library not found for -lSDLmain
How do I fix this?
make doesn't know where to find SDLmain; I need to link to the directory using link_directory in `CMakeLists.txt.
Running
$ g++-4.7 -std=c++0x ../src/*.cpp `sdl-config --libs`
works fine, so I've clearly got SDL installed correctly. Checking the output of sdl-config --libs:
$ sdl-config --libs
-L/opt/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa
So the thing that's not in the CMakeLists.txt is the -L/opt/local/lib. That should be added into the CMakeLists.txt using link_directory:
link_directories( /opt/local/lib )
And then cmake runs fine.