I am using the Raspberry pi 4 HX711 to measure weight of the objects. I use the https://github.com/endail/hx711.git . I write CMakeLists.txt instead of Makefile.
Once the build the project i got the following error.
STATUS:Today Date is 2024-01-27
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fruitspi/Fruits/weightingScale/build
[ 11%] Building CXX object CMakeFiles/weightCell.dir/Calibration.cpp.o
[ 22%] Building CXX object CMakeFiles/weightCell.dir/src/AbstractScale.cpp.o
[ 33%] Building CXX object CMakeFiles/weightCell.dir/src/HX711.cpp.o
[ 44%] Building CXX object CMakeFiles/weightCell.dir/src/Mass.cpp.o
[ 55%] Building CXX object CMakeFiles/weightCell.dir/src/Utility.cpp.o
[ 66%] Building CXX object CMakeFiles/weightCell.dir/src/Value.cpp.o
[ 77%] Building CXX object CMakeFiles/weightCell.dir/src/ValueStack.cpp.o
[ 88%] Building CXX object CMakeFiles/weightCell.dir/src/Watcher.cpp.o
[100%] Linking CXX executable weightCell
/usr/bin/ld: CMakeFiles/weightCell.dir/Calibration.cpp.o: in function `main':
Calibration.cpp:(.text.startup+0xfc): undefined reference to `HX711::SimpleHX711::SimpleHX711(int, int, HX711::Value, HX711::Value, HX711::Rate)'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::_throwGpioExIfErr(int)':
Utility.cpp:(.text+0x2c): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::openGpioHandle(int)':
Utility.cpp:(.text+0x88): undefined reference to `lgGpiochipOpen'
/usr/bin/ld: Utility.cpp:(.text+0xa8): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::closeGpioHandle(int)':
Utility.cpp:(.text+0xf8): undefined reference to `lgGpiochipClose'
/usr/bin/ld: Utility.cpp:(.text+0x118): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::openGpioInput(int, int)':
Utility.cpp:(.text+0x170): undefined reference to `lgGpioClaimInput'
/usr/bin/ld: Utility.cpp:(.text+0x190): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::openGpioOutput(int, int)':
Utility.cpp:(.text+0x1ec): undefined reference to `lgGpioClaimOutput'
/usr/bin/ld: Utility.cpp:(.text+0x20c): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::closeGpioPin(int, int)':
Utility.cpp:(.text+0x25c): undefined reference to `lgGpioFree'
/usr/bin/ld: Utility.cpp:(.text+0x27c): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::readGpio(int, int)':
Utility.cpp:(.text+0x2cc): undefined reference to `lgGpioRead'
/usr/bin/ld: Utility.cpp:(.text+0x2f4): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::writeGpio(int, int, HX711::GpioLevel)':
Utility.cpp:(.text+0x344): undefined reference to `lgGpioWrite'
/usr/bin/ld: Utility.cpp:(.text+0x364): undefined reference to `lguErrorText'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/weightCell.dir/build.make:209: weightCell] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/weightCell.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Code:
cmake_minimum_required(VERSION 3.18)project(weightCell VERSION 1.0.0)set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")# use c++ 17set(CMAKE_CXX_STANDARD 11)set(CMAKE_CXX_STANDARD_REQUIRED True)set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_FLAGS "-Wall -Wextra Wfatal-errors -fomit-frame-pointer -pipe ")set(CMAKE_CXX_FLAGS "-O2 -fstack-clash-protection -Wl,-z,defs -mfpu=vfp -march=native")#set(CMAKE_CXX_FLAGS " -Wl, -z, relo")string(TIMESTAMP TODAY "%Y-%m-%d")message(STATUS: "Today Date is ${TODAY}")include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)FILE(GLOB_RECURSE SRC_FILES src/*.cpp)FILE(GLOB_RECURSE HDR_FILES include/*.h)find_package(Threads REQUIRED)include_directories(/usr/local/include/hx711)add_executable(weightCell Calibration.cpp ${SRC_FILES} ${HDR_FILES})target_link_libraries(weightCell PUBLIC ${libhx711} ${llgpio})target_link_libraries(weightCell PRIVATE Threads::Threads)
STATUS:Today Date is 2024-01-27
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fruitspi/Fruits/weightingScale/build
[ 11%] Building CXX object CMakeFiles/weightCell.dir/Calibration.cpp.o
[ 22%] Building CXX object CMakeFiles/weightCell.dir/src/AbstractScale.cpp.o
[ 33%] Building CXX object CMakeFiles/weightCell.dir/src/HX711.cpp.o
[ 44%] Building CXX object CMakeFiles/weightCell.dir/src/Mass.cpp.o
[ 55%] Building CXX object CMakeFiles/weightCell.dir/src/Utility.cpp.o
[ 66%] Building CXX object CMakeFiles/weightCell.dir/src/Value.cpp.o
[ 77%] Building CXX object CMakeFiles/weightCell.dir/src/ValueStack.cpp.o
[ 88%] Building CXX object CMakeFiles/weightCell.dir/src/Watcher.cpp.o
[100%] Linking CXX executable weightCell
/usr/bin/ld: CMakeFiles/weightCell.dir/Calibration.cpp.o: in function `main':
Calibration.cpp:(.text.startup+0xfc): undefined reference to `HX711::SimpleHX711::SimpleHX711(int, int, HX711::Value, HX711::Value, HX711::Rate)'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::_throwGpioExIfErr(int)':
Utility.cpp:(.text+0x2c): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::openGpioHandle(int)':
Utility.cpp:(.text+0x88): undefined reference to `lgGpiochipOpen'
/usr/bin/ld: Utility.cpp:(.text+0xa8): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::closeGpioHandle(int)':
Utility.cpp:(.text+0xf8): undefined reference to `lgGpiochipClose'
/usr/bin/ld: Utility.cpp:(.text+0x118): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::openGpioInput(int, int)':
Utility.cpp:(.text+0x170): undefined reference to `lgGpioClaimInput'
/usr/bin/ld: Utility.cpp:(.text+0x190): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::openGpioOutput(int, int)':
Utility.cpp:(.text+0x1ec): undefined reference to `lgGpioClaimOutput'
/usr/bin/ld: Utility.cpp:(.text+0x20c): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::closeGpioPin(int, int)':
Utility.cpp:(.text+0x25c): undefined reference to `lgGpioFree'
/usr/bin/ld: Utility.cpp:(.text+0x27c): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::readGpio(int, int)':
Utility.cpp:(.text+0x2cc): undefined reference to `lgGpioRead'
/usr/bin/ld: Utility.cpp:(.text+0x2f4): undefined reference to `lguErrorText'
/usr/bin/ld: CMakeFiles/weightCell.dir/src/Utility.cpp.o: in function `HX711::Utility::writeGpio(int, int, HX711::GpioLevel)':
Utility.cpp:(.text+0x344): undefined reference to `lgGpioWrite'
/usr/bin/ld: Utility.cpp:(.text+0x364): undefined reference to `lguErrorText'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/weightCell.dir/build.make:209: weightCell] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/weightCell.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Statistics: Posted by jaganathang — Sat Jan 27, 2024 3:37 pm