Qt5 cmake cannot find header file of ui - cmake

I'm creating a cmake project of my Qt5 application. Now when I compile my application using cmake in Clion I got a fatal error.
My CMakeLists.txt file looks like:
cmake_minimum_required(VERSION 2.8.11)
project(Oefening11_kv)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set (CMAKE_PREFIX_PATH C:\\Qt\\Qt5.8.0\\5.8\\mingw53_32\\lib\\cmake\\)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets)
find_package(Qt5Gui)
find_package(Qt5Charts)
set(Oefening11_kv_SOURCES main.cpp oefening11a.cpp oefening11b.cpp oefening11c.cpp)
set(Oefening11_kv_HEADERS oefening11a.h oefening11b.h oefening11c.h)
set(Oefening11_kv_FORMS oefening11a.ui)
QT5_WRAP_CPP(Oefening11_kv_HEADERS_MOC ${Oefening11_kv_HEADERS})
QT5_WRAP_UI(Oefening11_kv_FORMS_HEADERS ${Oefening11_kv_FORMS})
add_library(Oefening11_kv_CONFIG ${Oefening11_kv_HEADERS_MOC} ${Oefening11_kv_FORMS_HEADERS})
QT5_USE_MODULES(Oefening11_kv_CONFIG Widgets)
add_executable(Oefening11_kv ${Oefening11_kv_SOURCES} ${Oefening11_kv_CONFIG})
QT5_USE_MODULES(Oefening11_kv Core Gui Widgets Charts)
The error that Clion is trowing when I compile the application is:
oefening11a.cpp:21: undefined reference to
__imp__ZN8QtCharts11QLineSeriesC1EP7QObject' oefening11a.cpp:26:
undefined reference to__imp__ZN8QtCharts9QXYSeries6appendEdd'
oefening11a.cpp:30: undefined reference to
__imp__ZN8QtCharts6QChartC1EP13QGraphicsItem6QFlagsIN2Qt10WindowTypeEE' oefening11a.cpp:31: undefined reference to
__imp__ZN8QtCharts6QChart9addSeriesEPNS_15QAbstractSeriesE'
oefening11a.cpp:32: undefined reference to
__imp__ZNK8QtCharts6QChart6legendEv' oefening11a.cpp:33: undefined
reference to__imp__ZN8QtCharts6QChart8setTitleERK7QString'
oefening11a.cpp:36: undefined reference to
__imp__ZN8QtCharts10QValueAxisC1EP7QObject' oefening11a.cpp:37:
undefined reference to
__imp__ZN8QtCharts10QValueAxis14setLabelFormatERK7QString'
oefening11a.cpp:38: undefined reference to
__imp__ZN8QtCharts13QAbstractAxis12setTitleTextERK7QString'
oefening11a.cpp:39: undefined reference to
__imp__ZN8QtCharts6QChart7addAxisEPNS_13QAbstractAxisE6QFlagsIN2Qt13AlignmentFlagEE'
oefening11a.cpp:40: undefined reference to
__imp__ZN8QtCharts15QAbstractSeries10attachAxisEPNS_13QAbstractAxisE'
oefening11a.cpp:43: undefined reference to
__imp__ZN8QtCharts10QValueAxisC1EP7QObject' oefening11a.cpp:44:
undefined reference to
__imp__ZN8QtCharts10QValueAxis14setLabelFormatERK7QString'
oefening11a.cpp:45: undefined reference to
__imp__ZN8QtCharts13QAbstractAxis12setTitleTextERK7QString'
oefening11a.cpp:46: undefined reference to
__imp__ZN8QtCharts6QChart7addAxisEPNS_13QAbstractAxisE6QFlagsIN2Qt13AlignmentFlagEE'
oefening11a.cpp:47: undefined reference to
__imp__ZN8QtCharts15QAbstractSeries10attachAxisEPNS_13QAbstractAxisE'
oefening11a.cpp:50: undefined reference to
__imp__ZN8QtCharts10QChartViewC1EPNS_6QChartEP7QWidget'
oefening11a.cpp:51: undefined reference to
__imp__ZN13QGraphicsView13setRenderHintEN8QPainter10RenderHintEb'
oefening11a.cpp:54: undefined reference to
__imp__ZN11QMainWindow16setCentralWidgetEP7QWidget'
oefening11a.cpp:73: undefined reference to
__imp__ZN10QStatusBar11showMessageERK7QStringi' t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x38):
undefined reference to QMainWindow::event(QEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x40):
undefined reference toQObject::eventFilter(QObject*, QEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x48):
undefined reference to QObject::timerEvent(QTimerEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x50):
undefined reference toQObject::childEvent(QChildEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x58):
undefined reference to QObject::customEvent(QEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x60):
undefined reference toQObject::connectNotify(QMetaMethod const&)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x68):
undefined reference to QObject::disconnectNotify(QMetaMethod const&)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x70):
undefined reference toQWidget::devType() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x78):
undefined reference to QWidget::setVisible(bool)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x80):
undefined reference toQWidget::sizeHint() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x88):
undefined reference to QWidget::minimumSizeHint() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x90):
undefined reference toQWidget::heightForWidth(int) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x98):
undefined reference to QWidget::hasHeightForWidth() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xa0):
undefined reference toQWidget::paintEngine() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xa8):
undefined reference to QWidget::mousePressEvent(QMouseEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xb0):
undefined reference toQWidget::mouseReleaseEvent(QMouseEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xb8):
undefined reference to QWidget::mouseDoubleClickEvent(QMouseEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xc0):
undefined reference toQWidget::mouseMoveEvent(QMouseEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xc8):
undefined reference to QWidget::wheelEvent(QWheelEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xd0):
undefined reference toQWidget::keyPressEvent(QKeyEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xd8):
undefined reference to QWidget::keyReleaseEvent(QKeyEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xe0):
undefined reference toQWidget::focusInEvent(QFocusEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xe8):
undefined reference to QWidget::focusOutEvent(QFocusEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xf0):
undefined reference toQWidget::enterEvent(QEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0xf8):
undefined reference to QWidget::leaveEvent(QEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x100):
undefined reference toQWidget::paintEvent(QPaintEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x108):
undefined reference to QWidget::moveEvent(QMoveEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x110):
undefined reference toQWidget::resizeEvent(QResizeEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x118):
undefined reference to QWidget::closeEvent(QCloseEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x120):
undefined reference to
QMainWindow::contextMenuEvent(QContextMenuEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x128):
undefined reference to QWidget::tabletEvent(QTabletEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x130):
undefined reference toQWidget::actionEvent(QActionEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x138):
undefined reference to QWidget::dragEnterEvent(QDragEnterEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x140):
undefined reference toQWidget::dragMoveEvent(QDragMoveEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x148):
undefined reference to QWidget::dragLeaveEvent(QDragLeaveEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x150):
undefined reference toQWidget::dropEvent(QDropEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x158):
undefined reference to QWidget::showEvent(QShowEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x160):
undefined reference toQWidget::hideEvent(QHideEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x168):
undefined reference to QWidget::nativeEvent(QByteArray const&, void*,
long*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x170):
undefined reference toQWidget::changeEvent(QEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x178):
undefined reference to
QWidget::metric(QPaintDevice::PaintDeviceMetric) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x180):
undefined reference toQWidget::initPainter(QPainter*) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x188):
undefined reference to QWidget::redirected(QPoint*) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x190):
undefined reference toQWidget::sharedPainter() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x198):
undefined reference to QWidget::inputMethodEvent(QInputMethodEvent*)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1a0):
undefined reference to
QWidget::inputMethodQuery(Qt::InputMethodQuery) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1a8):
undefined reference to QWidget::focusNextPrevChild(bool)'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1b0):
undefined reference toQMainWindow::createPopupMenu()'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1d8):
undefined reference to non-virtual thunk to QWidget::devType() const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1e0):
undefined reference tonon-virtual thunk to QWidget::paintEngine()
const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1e8):
undefined reference to non-virtual thunk to
QWidget::metric(QPaintDevice::PaintDeviceMetric) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1f0):
undefined reference tonon-virtual thunk to
QWidget::initPainter(QPainter*) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x1f8):
undefined reference to non-virtual thunk to
QWidget::redirected(QPoint*) const'
t_automoc.cpp:(.rdata$_ZTV11Oefening11A[_ZTV11Oefening11A]+0x200):
undefined reference tonon-virtual thunk to QWidget::sharedPainter()
const'
Can't find the problem in my cmake file. Can someone help me with this?

Ok I found the issue. I was using a x64 compiler on x86 QT5 libraries. When changing the compiler to a x86 one it compiles.

Besides moc, you will need to run uic as well:
set(CMAKE_AUTOUIC ON)

Related

Undefined reference to klee when building s2e

I'm trying to start a new prject and build s2e in a new directory. But at arounf the 100% mark, it gives me an undefined reference error. The relevant part (imo) is this:
[ 92%] Linking CXX executable ../ExprTest
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/source/s2e/klee/include/klee/Internal/Module/KModule.h:189: undefined reference to `klee::KModule::KModule(llvm::Module*)'
My directory structure is such:
|-s2e-env
|-s2e_projects
|-venv
I followed the steps from here: http://s2e.systems/docs/s2e-env.html I followed all the steps upto s2e build which is where this problem occurs.
For reference, the (truncated) output which I got from doing s2e build &> log:
[ 88%] Built target kleeModule
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Leaving directory '~/s2e_projects/build/klee-release'
make[3]: Leaving directory '~/s2e_projects/build/klee-release'
make[3]: Leaving directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
make[3]: Entering directory '~/s2e_projects/build/klee-release'
[ 91%] Linking CXX executable ../ADTTest
[ 91%] Linking CXX executable ../UtilsTest
[ 92%] Linking CXX executable ../ExprTest
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/source/s2e/klee/include/klee/Internal/Module/KModule.h:189: undefined reference to `klee::KModule::KModule(llvm::Module*)'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/build/llvm-10.0.0.src/include/llvm/IR/DataLayout.h:393: undefined reference to `llvm::DataLayout::getPointerSize(unsigned int) const'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::setModule(llvm::Module*, klee::Interpreter::ModuleOptions const&, bool)':
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:107: undefined reference to `klee::KModule::linkLibraries(klee::Interpreter::ModuleOptions const&)'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:108: undefined reference to `klee::KModule::buildShadowStructures()'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:110: undefined reference to `klee::KModule::prepare(klee::Interpreter::ModuleOptions const&, klee::InterpreterHandler*)'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobalObject(klee::ExecutionState&, boost::intrusive_ptr<klee::ObjectState> const&, llvm::Constant const*, unsigned int)':
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:150: undefined reference to `llvm::ConstantDataSequential::getNumElements() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:151: undefined reference to `llvm::ConstantDataSequential::getElementAsConstant(unsigned int) const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:153: undefined reference to `llvm::DataLayout::getStructLayout(llvm::StructType*) const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:158: undefined reference to `klee::KModule::evalConstant(std::unordered_map<llvm::GlobalValue const*, klee::ref<klee::ConstantExpr>, std::hash<llvm::GlobalValue const*>, std::equal_to<llvm::GlobalValue const*>, std::allocator<std::pair<llvm::GlobalValue const* const, klee::ref<klee::ConstantExpr> > > > const&, llvm::Constant const*, klee::KInstruction const*)'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:163: undefined reference to `klee::ConstantExpr::ZExt(unsigned int)'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobals(klee::ExecutionState&)':
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:200: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:241: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:247: undefined reference to `llvm::GlobalValue::isDeclaration() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:258: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:260: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:262: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:268: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:281: undefined reference to `llvm::Value::getName() const'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:306: undefined reference to `klee::KModule::evalConstant(std::unordered_map<llvm::GlobalValue const*, klee::ref<klee::ConstantExpr>, std::hash<llvm::GlobalValue const*>, std::equal_to<llvm::GlobalValue const*>, std::allocator<std::pair<llvm::GlobalValue const* const, klee::ref<klee::ConstantExpr> > > > const&, llvm::Constant const*, klee::KInstruction const*)'
~/s2e_projects/source/s2e/klee/lib/Core/Executor.cpp:311: undefined reference to `llvm::Value::getName() const'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobals(klee::ExecutionState&)':
~/s2e_projects/build/llvm-10.0.0.src/include/llvm/IR/GlobalVariable.h:92: undefined reference to `llvm::GlobalValue::isDeclaration() const'
../../lib/libkleeCore.a(Executor.cpp.o): In function `klee::Executor::initializeGlobals(klee::ExecutionState&)':
...
I had the exact same error and solved it with:
sudo apt install gcc-9 g++-9
Also check to make sure clang selects the installed gcc-9 toolchain:
$ PATH_TO_S2E/install/bin/clang++ -v
...
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
...
As for why a compatible gcc toolchain is needed, even though clang is used to compile S2E:
Why clang selects a gcc installation?

Linking C++ on Rust: undefined reference to `operator delete(void*)' and `__gxx_personality_v0', libstdc++ missing?

I'm trying to build a cpp cmake project and link to my Rust project.
cmake_minimum_required(VERSION 3.0)
set (CMAKE_CXX_STANDARD 17)
project(ZLMediaKit_LIB CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(ENABLE_TESTS OFF FORCE)
option(ENABLE_TESTS OFF)
set(ENABLE_OPENSSL FALSE FORCE)
option(ENABLE_OPENSSL OFF)
add_subdirectory(ZLMediaKit)
add_library(libzlmediakit_cpp_interface STATIC interface.cpp)
target_include_directories(libzlmediakit_cpp_interface PUBLIC
.
${CMAKE_CURRENT_SOURCE_DIR}/ZLMediaKit/src
${CMAKE_CURRENT_SOURCE_DIR}/ZLMediaKit/3rdpart/ZLToolKit/src)
target_link_libraries(libzlmediakit_cpp_interface zlmediakit zltoolkit mpeg mov flv libstdc++)
install(TARGETS libzlmediakit_cpp_interface DESTINATION .)
Here's my build.rs:
extern crate cmake;
use cmake::Config;
fn main()
{
let dst = Config::new("zlmediakit_lib").build();
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=libzlmediakit_cpp_interface");
}
But I'm getting undefined reference errors:
ong)':
/usr/include/c++/9/ext/new_allocator.h:128: undefined reference to `operator delete(void*)'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `ZLRTSPClient::~ZLRTSPClient()':
/home/dev/orwell/liborwell_rust/zlmediakit_rust/zlmediakit_lib/ZLRTSPClient.h:14: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `std::default_delete<ZLRTSPClient>::operator()(ZLRTSPClient*) const':
/usr/include/c++/9/bits/unique_ptr.h:81: undefined reference to `operator delete(void*, unsigned long)'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: /usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o):(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
I've researched and found some answers (Link error "undefined reference to `__gxx_personality_v0'" and g++) that old me to link against libstdc++. As you see, I'm already doing that.
If I try to compile the CMake project alone, it links sucessfully. However then I compile everything from the Rust side, it gives this error.
Complete output of rust compilation

CMake undefined reference with statically linked libraries

I am kinda new to CMake and trying to learn it. Im trying to compile an example project from an IDE with CMake. A problem arises when i try to link some of the vendor supplied static libraries.
The Project is basically:
PROJECT_DIR
source
main.c
include
main.h
device
familyfolder
morefolders
emlib
src
somesource.c
em_core.c
...
inc
someheader.h
em_core.h
...
protocol
bluetooth/lib
EFR32BG1P
libbluetooth.a
librail.a
libnvm3.a
...
bluetooth/ble_stack
src
host
gecko_bglib.c
soc
...
inc
soc
native_gecko.h
someheader1.h
someheader2.h
...
host
someheader3.h
common
bg_types.h (which is included by native_gecko.h)
someheader4.h
CMakeLists.txt within root of project
# Base EFM32 CMake file
#
# This can be used as is as a project base, or by adding the efm32-base
# repository as a submodule to another project, copying this CMakeLists file
# to the top level directory, and updating the BASE_LOCATION variable to reflect this
# change
#
## Copyright (c) 2016 Ryan Kurte
# This file is covered under the MIT license available at: https://opensource.org/licenses/MIT
###### Project Environment #####
# Set minimum CMake version
cmake_minimum_required(VERSION 2.8.4)
# Optional verbose mode, uncomment or pass in -DCMAKE_VERBOSE_MAKEFILE=ON
# set(CMAKE_VERBOSE_MAKEFILE ON)
set(BASE_LOCATION .)
# Set the compiler (must be prior to project setup)
include(${BASE_LOCATION}/toolchain/arm-gcc.cmake)
##### Project Setup #####
# Configure project and languages
project(efm32-test C CXX ASM)
# ${DEVICE} sets the target specific model name
if (NOT DEVICE)
set(DEVICE EFR32BG1P232F256GM48)
# set(DEVICE BGM13P22F512GA)
set(BOARD BRD4100A)
# set(BLE_LIB EFR32BG13P)
endif ()
# ${JLINK_DEVICE} device model setting specifically for JLink. (Defaults to ${DEVICE} when not set)
# set(JLINK_DEVICE EFM32TG11BXXXF128)
# When ${JLINK_SERVER_IP} is set, JLink will try to connect over IP to a JLink server
# set(JLINK_SERVER_IP 127.0.0.1)
# Set build
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE DEBUG)
endif ()
##### Modules #####
# Libraries can be added to the LIBS variable
# or manually included here.
# Add base libs (emlib, CMSIS, device files)
include(${BASE_LOCATION}/toolchain/efm32-base.cmake)
add_subdirectory(${BASE_LOCATION}/cmsis)
add_subdirectory(${BASE_LOCATION}/emlib)
add_subdirectory(${BASE_LOCATION}/emdrv)
add_subdirectory(${BASE_LOCATION}/device)
add_subdirectory(${BASE_LOCATION}/protocol)
add_subdirectory(${BASE_LOCATION}/hardware)
add_subdirectory(${BASE_LOCATION}/radio)
# This is normally set in efm32-base.cmake, but libraries may modify it so set
# it after libraries/subdirectories have been added
set(CMAKE_EXE_LINKER_FLAGS "${COMMON_DEFINITIONS} -Xlinker -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -Wl,-v")
##### Files #####
# Add project headers
include_directories(${BASE_LOCATION}/include)
# Generate executable and link
add_executable(${PROJECT_NAME}
source/main.c
source/init_mcu.c
source/init_board.c
source/init_app.c
source/gatt_db.c
source/pti.c
source/app.c
source/application_properties.c)
efm32_configure_linker_addresses(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} ${LIBS} emlib emdrv cmsis device radio)
# Link optional libraries if available
if (${HAS_HARDWARE})
target_link_libraries(${PROJECT_NAME} hardware)
endif ()
if (${HAS_PROTOCOL})
target_link_libraries(${PROJECT_NAME} protocol)
endif ()
##### Post build #####
# Add post build commands
include(${BASE_LOCATION}/toolchain/post-build.cmake)
# Add JLink commands
include(${BASE_LOCATION}/toolchain/jlink.cmake)
##### CMake debug prints #####
if (CMAKE_VERBOSE_MAKEFILE)
print_debug_info()
endif()
CMakeLists.txt within emlib
# EFM32 Emlib CMake file
project(emlib)
# find . -name '*.c' | sort -u
add_library(${PROJECT_NAME}
src/em_core.c
src/alot_other_files.c)
target_include_directories(${PROJECT_NAME} PUBLIC inc)
target_link_libraries(${PROJECT_NAME} device protocol)
CMakeList.txt within protocol
project(protocol)
string(TOLOWER ${DEVICE} DEVICE_L)
set(BLE_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/ble_stack/linker/GCC/${DEVICE_L}.ld")
if (NOT EXISTS ${BLE_LINKER_SCRIPT})
message("No bluetooth specific linker script defined, skipping protocol")
set(HAS_PROTOCOL FALSE PARENT_SCOPE)
return()
endif ()
set(HAS_PROTOCOL TRUE PARENT_SCOPE)
message("Found bluetooth specific linker script, using this instead:\n before: ${LINKER_SCRIPT}\n after: ${BLE_LINKER_SCRIPT}")
set(LINKER_SCRIPT ${BLE_LINKER_SCRIPT} PARENT_SCOPE)
add_library(${PROJECT_NAME}
bluetooth/ble_stack/src/host/gecko_bglib.c)
# bluetooth/ble_stack/src/soc/rtos_bluetooth.c)
target_include_directories(${PROJECT_NAME} PUBLIC
bluetooth/ble_stack/inc/soc
bluetooth/ble_stack/inc/host
bluetooth/ble_stack/inc/common)
target_link_libraries(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libmbedtls.a
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libcoex.a
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libpsstore.a
emlib)
target_link_libraries(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a
emlib)
target_link_libraries(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/librail.a
emlib)
target_link_libraries(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a
emlib)
Start if main.c - the includes of which native_gecko.h is the main one.
/* Board headers */
#include "init_mcu.h"
#include "init_board.h"
#include "init_app.h"
#include "ble-configuration.h"
#include "board_features.h"
/* Bluetooth stack headers */
#include "bg_types.h"
#include "native_gecko.h"
#include "gatt_db.h"
/* Libraries containing default Gecko configuration values */
#include "em_emu.h"
#include "em_cmu.h"
When i try to include the static libraries and link them to the dependency of emlib
target_link_libraries(protocol PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/librail.a
emlib)
in a CMakeLists.txt file in the protocol folder, im getting a
undefined reference to some function
which should be in the libs folder and also is getting compiled beforehand.
As asked, more or less the full error part. which is at the moment mostly a repetition of static library dependency errors.
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(smp.c.obj): In function `smp_state_master_idle':
smp.c:(.text.smp_state_master_idle+0x298): undefined reference to `mbedtls_mpi_free'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(smp.c.obj): In function `smp_init':
smp.c:(.text.smp_init+0x4c): undefined reference to `mbedtls_ecp_group_init'
smp.c:(.text.smp_init+0x54): undefined reference to `mbedtls_ecp_group_load'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(sl_malloc.c.obj): In function `sl_malloc':
sl_malloc.c:(.text.sl_malloc+0x4): undefined reference to `CORE_EnterCritical'
sl_malloc.c:(.text.sl_malloc+0x14): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(sl_malloc.c.obj): In function `sl_free':
sl_malloc.c:(.text.sl_free+0x4): undefined reference to `CORE_EnterCritical'
sl_malloc.c:(.text.sl_free+0x16): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(vectors_efr32xg1x.c.obj): In function `vectors_register':
vectors_efr32xg1x.c:(.text.vectors_register+0x6): undefined reference to `CORE_SetNvicRamTableHandler'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(vectors_efr32xg1x.c.obj): In function `vectors_init':
vectors_efr32xg1x.c:(.text.vectors_init+0x1c): undefined reference to `CORE_InitNvicVectorTable'
vectors_efr32xg1x.c:(.text.vectors_init+0x24): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x2c): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x34): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x3c): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x44): undefined reference to `CORE_SetNvicRamTableHandler'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(vectors_efr32xg1x.c.obj):vectors_efr32xg1x.c:(.text.vectors_init+0x4c): more undefined references to `CORE_SetNvicRamTableHandler' follow
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(bg_random_aes.c.obj): In function `aes_ctr_encrypt':
bg_random_aes.c:(.text.aes_ctr_encrypt+0x26): undefined reference to `mbedtls_aes_setkey_enc'
bg_random_aes.c:(.text.aes_ctr_encrypt+0x3a): undefined reference to `mbedtls_aes_crypt_ctr'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(bg_util_aes.c.obj): In function `bg_init_aes_context':
bg_util_aes.c:(.text.bg_init_aes_context+0x2): undefined reference to `mbedtls_aes_init'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf.o): In function `RAILINT_e0dfaecc04939a24e643c7a83fed51fa':
rail_rf.c:(.text.RAILInt_SetChannel+0x6): undefined reference to `CORE_EnterCritical'
rail_rf.c:(.text.RAILInt_SetChannel+0x28): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf_hal.o): In function `RAILINT_2d49aecfcb6d27d54075c2234a55d5e7':
rail_rf_hal.c:(.text.RFHAL_ConfigRxOptions+0x8c): undefined reference to `CORE_EnterCritical'
rail_rf_hal.c:(.text.RFHAL_ConfigRxOptions+0xb0): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf_hal.o): In function `RAILINT_3212ddcec5ace9cb56e8f1cb3ca8d33c':
rail_rf_hal.c:(.text.RFHAL_SetTimer+0x1a): undefined reference to `CORE_EnterCritical'
rail_rf_hal.c:(.text.RFHAL_SetTimer+0x5a): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf_hal.o): In function `RAILINT_39475387e0cb29596ec425b4cfae76fb':
rail_rf_hal.c:(.text.RFHAL_GetRxPacketInfo+0x1a): undefined reference to `CORE_EnterCritical'
rail_rf_hal.c:(.text.RFHAL_GetRxPacketInfo+0x30): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_calibration.o): In function `RAILINT_3f0b6529856489702e1c986caf70e7aa':
rail_calibration.c:(.text.RAILInt_PendCal+0x6): undefined reference to `CORE_EnterCritical'
rail_calibration.c:(.text.RAILInt_PendCal+0x14): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_8309d0303dd52c35776f1b9d204e124b':
rfhal_bufc.c:(.text.BUFC_SetTxBuffer+0xa): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_SetTxBuffer+0x26): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_ea701df21b15aeabbf4f1b9be517a6fb':
rfhal_bufc.c:(.text.BUFC_RxBufferReset+0x2): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_RxBufferReset+0x64): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_e5f98ee4df05ffeec0898fd3dfcac7ef':
rfhal_bufc.c:(.text.BUFC_ReleaseRxPacket+0xa): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_ReleaseRxPacket+0x2c): undefined reference to `CORE_ExitCritical'
rfhal_bufc.c:(.text.BUFC_ReleaseRxPacket+0xda): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_ee328b192a18bb4569d7a778a9299c02':
rfhal_bufc.c:(.text.BUFC_GetRxPacketInfo+0xa): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_GetRxPacketInfo+0x4c): undefined reference to `CORE_ExitCritical'
rfhal_bufc.c:(.text.BUFC_GetRxPacketInfo+0xfa): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_protimer.o): In function `RAILINT_fea48c6a0a5dcb75b3cd7e0e0188d110':
rfhal_protimer.c:(.text.PROTIMER_CCTimerStart+0xa): undefined reference to `CORE_EnterCritical'
rfhal_protimer.c:(.text.PROTIMER_CCTimerStart+0x1c): undefined reference to `CORE_ExitCritical'
rfhal_protimer.c:(.text.PROTIMER_CCTimerStart+0x44): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_protimer.o): In function `RAILINT_6d18a45e267fa35e89a132429cb09fd9':
rfhal_protimer.c:(.text.PROTIMER_CheckCcaReallyFailed+0x4): undefined reference to `CORE_EnterAtomic'
rfhal_protimer.c:(.text.PROTIMER_CheckCcaReallyFailed+0xa2): undefined reference to `CORE_ExitAtomic'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_radio.o): In function `RAILINT_49c1638648869baaf18ca93f541e7dd3':
rfhal_radio.c:(.text.RADIO_GetRssi+0xc): undefined reference to `CORE_EnterCritical'
rfhal_radio.c:(.text.RADIO_GetRssi+0x36): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_rtccsync.o): In function `RAILINT_b3ae6c670ad30ab880888943a58faee0':
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0x12): undefined reference to `CORE_EnterCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0xda): undefined reference to `CORE_ExitCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0x1cc): undefined reference to `CORE_ExitCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0x21a): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_rtccsync.o): In function `RAILINT_b59eec27e1e4352a569b2404f6e35a1b':
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0x24): undefined reference to `CORE_EnterCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0xe6): undefined reference to `CORE_ExitCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0x124): undefined reference to `CORE_EnterCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0x166): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_rand.o): In function `RAILINT_06d3d408af442bc7f395514867b33be3':
rfhal_rand.c:(.text.RFRAND_GetRadioEntropy+0x36): undefined reference to `CORE_EnterCritical'
rfhal_rand.c:(.text.RFRAND_GetRadioEntropy+0xa0): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_5f7114cf3ce03d53615d89fe78177694':
generic_phy.c:(.text.GENERIC_PHY_ConfigureRollbackReporting+0x4): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureRollbackReporting+0x46): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_933bfa2aa7cb94f384fd9482dc3d4942':
generic_phy.c:(.text.RADIO_RACRxAbort+0x2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.RADIO_RACRxAbort+0x2c): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_661cd5b832e0dc684eca55cf65a1a4bd':
generic_phy.c:(.text.GENERIC_PHY_DisableRadioIrqs+0x2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_DisableRadioIrqs+0x90): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_549ae7c6edbff50f2340752aad688b72':
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x2e): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x60): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0xa2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x2ec): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x5c): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_cc007e4287f0aeed09681d7e13e3e8eb':
generic_phy.c:(.text.GENERIC_PHY_PacketTx+0x2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_PacketTx+0x1c): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_PacketTx+0x30): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_0398a16a4bf50dbcafa68c979c0efcc9':
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0x14): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0x2a): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0x5e): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0xd0): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_c508b1e616a62d61aefaf693649607f1':
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x4): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x1e): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x5a): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x64): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_26621d98bc1a2dc74b7093edea89d850':
generic_phy.c:(.text.GENERIC_PHY_ResetRxFifo+0x4): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ResetRxFifo+0x1a): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_232b67d119ad2a1a23589ef6ecfa72b8':
generic_phy.c:(.text.GENERIC_PHY_RadioIdle+0x8): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_RadioIdle+0x26): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `FRC_IRQHandler':
generic_phy.c:(.text.FRC_IRQHandler+0x436): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.FRC_IRQHandler+0x466): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_1446b673acaddfc4b02974cda9fee981':
generic_phy.c:(.text.GENERIC_PHY_SetFeatures+0x6): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_SetFeatures+0x16): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_lock.c.obj): In function `nvm3_lockBegin':
nvm3_lock.c:(.text.nvm3_lockBegin+0x2): undefined reference to `CORE_EnterCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_lock.c.obj): In function `nvm3_lockEnd':
nvm3_lock.c:(.text.nvm3_lockEnd+0x4): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashWriteWords':
nvm3_hal_flash.c:(.text.nvm3_halFlashWriteWords+0xa): undefined reference to `MSC_WriteWord'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashClose':
nvm3_hal_flash.c:(.text.nvm3_halFlashClose+0x0): undefined reference to `MSC_Deinit'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashOpen':
nvm3_hal_flash.c:(.text.nvm3_halFlashOpen+0x2): undefined reference to `MSC_Init'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashPageErase':
nvm3_hal_flash.c:(.text.nvm3_halFlashPageErase+0x4): undefined reference to `MSC_ErasePage'
collect2: error: ld returned 1 exit status
CMakeFiles/efm32-test.dir/build.make:290: recipe for target 'efm32-test' failed
make[2]: *** [efm32-test] Error 1
CMakeFiles/Makefile2:261: recipe for target 'CMakeFiles/efm32-test.dir/all' failed
make[1]: *** [CMakeFiles/efm32-test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

How do I use SFML with CMake FetchContent?

So I'd like to get the SFML from the git tag directly using CMake FetchContent. Most of the tutorial are not using this, so I don't really know what to do, I use imgui-sfml-fetchcontent for the reference.
My CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
project(2DComputerGraphics)
set(CMAKE_CXX_STANDARD 17)
# SFML
set(SFML_VERSION "2.5.1")
FetchContent_Declare(
SFML
GIT_REPOSITORY "https://github.com/SFML/SFML.git"
GIT_TAG "${SFML_VERSION}"
)
FetchContent_GetProperties(SFML)
if(NOT SFML_POPULATED)
FetchContent_Populate(SFML)
add_subdirectory(${SFML_SOURCE_DIR} ${SFML_BINARY_DIR})
#
# message("SFML_SOURCE_DIR: ${SFML_SOURCE_DIR}")
# message("SFML_BINARY_DIR: ${SFML_BINARY_DIR}")
endif()
set(SOURCE
"main.cpp"
)
#
# message("Source: ${SOURCE}")
add_executable(2DComputerGraphicsApp
"${SOURCE}"
)
target_include_directories(2DComputerGraphicsApp PRIVATE
"${SFML_INCLUDE_DIR}"
)
#
# message("SFML_INCLUDE_DIR: ${SFML_INCLUDE_DIR}")
target_link_libraries(2DComputerGraphicsApp
"${SFML_LIBRARIES}"
"${SFML_DEPENDENCIES}"
)
#
# message("SFML_LIBRARIES: ${SFML_LIBRARIES}")
# message("SFML_DEPENDENCIES: ${SFML_DEPENDENCIES}")
target_compile_options(2DComputerGraphicsApp PRIVATE -Wall)
And it gives me this error
/usr/bin/ld: CMakeFiles/2DComputerGraphicsApp.dir/main.cpp.o: in function `main':
main.cpp:(.text+0x82): undefined reference to `sf::String::String(char const*, std::locale const&)'
/usr/bin/ld: main.cpp:(.text+0xa0): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: main.cpp:(.text+0xd3): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/usr/bin/ld: main.cpp:(.text+0x100): undefined reference to `sf::Texture::Texture()'
/usr/bin/ld: main.cpp:(.text+0x119): undefined reference to `sf::Texture::create(unsigned int, unsigned int)'
/usr/bin/ld: main.cpp:(.text+0x132): undefined reference to `sf::Sprite::Sprite(sf::Texture const&)'
/usr/bin/ld: main.cpp:(.text+0x152): undefined reference to `sf::Window::isOpen() const'
/usr/bin/ld: main.cpp:(.text+0x173): undefined reference to `sf::Window::pollEvent(sf::Event&)'
/usr/bin/ld: main.cpp:(.text+0x190): undefined reference to `sf::Window::close()'
/usr/bin/ld: main.cpp:(.text+0x1da): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
/usr/bin/ld: main.cpp:(.text+0x1f7): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
/usr/bin/ld: main.cpp:(.text+0x210): undefined reference to `sf::Texture::update(unsigned char const*)'
/usr/bin/ld: main.cpp:(.text+0x229): undefined reference to `sf::RenderStates::Default'
/usr/bin/ld: main.cpp:(.text+0x234): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/usr/bin/ld: main.cpp:(.text+0x243): undefined reference to `sf::Window::display()'
/usr/bin/ld: main.cpp:(.text+0x284): undefined reference to `sf::Texture::~Texture()'
/usr/bin/ld: main.cpp:(.text+0x293): undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: main.cpp:(.text+0x2fd): undefined reference to `sf::Texture::~Texture()'
/usr/bin/ld: main.cpp:(.text+0x311): undefined reference to `sf::RenderWindow::~RenderWindow()'
/usr/bin/ld: CMakeFiles/2DComputerGraphicsApp.dir/main.cpp.o: in function `sf::Sprite::~Sprite()':
main.cpp:(.text._ZN2sf6SpriteD2Ev[_ZN2sf6SpriteD5Ev]+0xf): undefined reference to `vtable for sf::Sprite'
/usr/bin/ld: main.cpp:(.text._ZN2sf6SpriteD2Ev[_ZN2sf6SpriteD5Ev]+0x1d): undefined reference to `vtable for sf::Sprite'
/usr/bin/ld: main.cpp:(.text._ZN2sf6SpriteD2Ev[_ZN2sf6SpriteD5Ev]+0x35): undefined reference to `sf::Transformable::~Transformable()'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/2DComputerGraphicsApp.dir/build.make:84: 2DComputerGraphicsApp] Error 1
make[3]: Leaving directory '/home/andraantariksa/Projects/2d-computer-graphics/build'
make[2]: *** [CMakeFiles/Makefile2:216: CMakeFiles/2DComputerGraphicsApp.dir/all] Error 2
make[2]: Leaving directory '/home/andraantariksa/Projects/2d-computer-graphics/build'
make[1]: *** [Makefile:130: all] Error 2
make[1]: Leaving directory '/home/andraantariksa/Projects/2d-computer-graphics/build'
make: *** [Makefile:2: build] Error 2
I think it happen because I did not link the SFML correctly. How do I solve this?
The variables are wrong. https://cmake.org/cmake/help/v3.16/module/FetchContent.html states that <name> has to be lower case. Also squareskittles is right, you shouldn't use ${SFML_LIBRARIES} / ${SFML_INCLUDE_DIR}, this is only valid if the old FindSFML.cmake is used.
cmake_minimum_required(VERSION 3.10)
include(FetchContent)
project(2DComputerGraphics)
set(CMAKE_CXX_STANDARD 17)
set(SFML_VERSION "2.5.1")
FetchContent_Declare(
sfml
GIT_REPOSITORY "https://github.com/SFML/SFML.git"
GIT_TAG "${SFML_VERSION}"
)
FetchContent_GetProperties(sfml)
if(NOT sfml_POPULATED)
FetchContent_Populate(sfml)
add_subdirectory(${sfml_SOURCE_DIR} ${sfml_BINARY_DIR})
endif()
set(SOURCE
main.cpp
)
add_executable(2DComputerGraphicsApp
${SOURCE}
)
target_link_libraries(2DComputerGraphicsApp
PRIVATE
sfml-audio
sfml-graphics
sfml-system
sfml-window
)
target_compile_options(2DComputerGraphicsApp PRIVATE -Wall)

Cannot properly link the libraries in CMakeLists

I have some troubles with linking the source files (I have added them as Libraries in my CMakeLists) with my main file. Here is my CMakeLists:
cmake_minimum_required(VERSION 2.8.3)
project(ros_bridge)
set(${PROJECT_NAME}_CATKIN_COMPONENTS
nav_msgs
roscpp
sensor_msgs
std_msgs
)
add_compile_options(-std=c++14)
find_package(catkin REQUIRED COMPONENTS ${${PROJECT_NAME}_CATKIN_COMPONENTS})
find_package(RapidJSON REQUIRED)
catkin_package(
INCLUDE_DIRS
include
include/aws_iot_sdk
include/common
include/network
CATKIN_DEPENDS ${${PROJECT_NAME}_CATKIN_COMPONENTS}
)
include_directories(
include
include/aws_iot_sdk
${catkin_INCLUDE_DIRS}
)
## Libraries
add_library(ros_client src/ros_client.cpp)
add_library(ConfigCommon include/common/ConfigCommon.cpp)
add_library(OpenSSL include/network/OpenSSL/OpenSSLConnection.cpp)
add_library(WebSocket include/network/WebSocket/WebSocketConnection.cpp)
add_executable(ros_bridge_node src/main.cpp)
## Lib links
target_link_libraries(ros_client ConfigCommon ${catkin_LIBRARIES} ${RapidJSON_LIBRARIES} OpenSSL WebSocket)
target_link_libraries(ConfigCommon ${catkin_LIBRARIES} ${RapidJSON_LIBRARIES} OpenSSL WebSocket)
target_link_libraries(ros_bridge_node ${catkin_LIBRARIES} ros_client ConfigCommon OpenSSL WebSocket ${RapidJSON_LIBRARIES})
So when the compiler tries to link my main file (which is ros_bridge_node) I get the error with the linkage:
ros_client.cpp:(.text+0x605): undefined reference to `awsiotsdk::util::Logging::GetLogSystem()'
ros_client.cpp:(.text+0x66d): undefined reference to `awsiotsdk::ResponseHelper::ToString[abi:cxx11](awsiotsdk::ResponseCode)'
CMakeFiles/ros_bridge_node.dir/src/ros_client.cpp.o: In function `ros_bridge::RosClient::RunPublish(int&)':
ros_client.cpp:(.text+0x8d9): undefined reference to `awsiotsdk::Utf8String::Create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_push'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `awsiotsdk::NetworkConnection::Read(std::vector<unsigned char, std::allocator<unsigned char> >&, unsigned long, unsigned long, unsigned long&)'
/home/abyl/master-wheel/devel/lib/libConfigCommon.so: undefined reference to `awsiotsdk::util::JsonParser::InitializeFromJsonFile(rapidjson::GenericDocument<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, rapidjson::CrtAllocator>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `SHA1'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_f_base64'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `awsiotsdk::network::OpenSSLConnection::IsPhysicalLayerConnected()'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_set_flags'
/home/abyl/master-wheel/devel/lib/libWebSocket.so: undefined reference to `BIO_new'
So how can I properly link the libraries against my Main file?
EDIT:
I have set the object files of aws_iot_sdk like this:
set(${aws_sdk} /home/ren/aws-iot-device-sdk-cpp/build/CMakeFiles/aws-iot-sdk-cpp.dir/src)
set_source_files_properties(
${aws_sdk_path}
PROPERTIES
EXTERNAL_OBJECT true
GENERATED true
)
And tried to link that against my main file:
target_link_libraries(ros_bridge_node ros_client ConfigCommon Open WebSocket wslay ${RapidJSON_LIBRARIES} ${catkin_LIBRARIES} -lssl ${aws_sdk})
But still getting the same linkage problem. May be I am linking the object files wrong? (Now all the linkage problem is from the aws_iot_sdk)