Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake Build Error #61

Open
chairmanfaust opened this issue Mar 28, 2024 · 10 comments
Open

CMake Build Error #61

chairmanfaust opened this issue Mar 28, 2024 · 10 comments

Comments

@chairmanfaust
Copy link

When attempting to build this project on my raspberry pi running debian bookworm i'm hitting this problem at the end of the build instructions:

`mqtt@mqtt:/serial2mqtt $ cd build/
mqtt@mqtt:
/serial2mqtt/build $ cmake ..
CMake Error at CMakeLists.txt:12 (find_package):
By not providing "Findeclipse-paho-mqtt-c.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"eclipse-paho-mqtt-c", but CMake did not find one.

Could not find a package configuration file provided by
"eclipse-paho-mqtt-c" with any of the following names:

eclipse-paho-mqtt-cConfig.cmake
eclipse-paho-mqtt-c-config.cmake

Add the installation prefix of "eclipse-paho-mqtt-c" to CMAKE_PREFIX_PATH
or set "eclipse-paho-mqtt-c_DIR" to a directory containing one of the above
files. If "eclipse-paho-mqtt-c" provides a separate development package or
SDK, be sure it has been installed.

-- Configuring incomplete, errors occurred!
See also "/home/mqtt/serial2mqtt/build/CMakeFiles/CMakeOutput.log".
`

@oven-lab
Copy link

oven-lab commented Aug 4, 2024

Same issue here.

@vortex314
Copy link
Owner

As I'm not a CMAKE expert, any suggestion is welcome, I'm spending most of my time in Rust these days.

@Gagns4395
Copy link
Contributor

I could progress a bit on that. Seems the paho lib must be built and installed:

christophe@serveur-u:~/serial2mqtt$ cd paho.mqtt.c/
christophe@serveur-u:~/serial2mqtt/paho.mqtt.c$ sudo cmake --build . --target install
christophe@serveur-u:~/serial2mqtt/paho.mqtt.c$ make

but this not sufficient, because there's a next error as the paho lib is not build static, therefore paho-mqtt3as-static is missing

That can be fixed by adding -DPAHO_WITH_SSL=true to the paho command:

cd paho.mqtt.c && cmake -DPAHO_BUILD_STATIC=true -DPAHO_WITH_SSL=true && make && cd ..

I found that potentially -DPAHO_WITH_MQTT_C=ON in both paho and serial2mqtt was about, however my tries weren't successful.

If you put the -DPAHO_BUILD_STATIC=true, the last error that is raised is:

CMake Error at CMakeLists.txt:14 (add_executable):
  Target "serial2mqtt" links to target
  "eclipse-paho-mqtt-c::paho-mqtt3as-static" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?

and indeed,

Consolidate compiler generated dependencies of target paho-mqtt3a-static
[ 30%] Building C object src/CMakeFiles/paho-mqtt3a-static.dir/MQTTAsync.c.o
[ 30%] Linking C static library libpaho-mqtt3a.a
[ 31%] Built target paho-mqtt3a-static

as only the non-SSL one is generated, but not the paho-mqtt3as-static

I don't know what to change in order to ask the paho build to install also the -DPAHO_BUILD_STATIC=true

@Gagns4395
Copy link
Contributor

I will correct myself.

eclipse-paho-mqtt-c::paho-mqtt3as-static in CMakeList.txt requires to use the SSL version, and therefore find_package(OpenSSL REQUIRED) must be added.

...
if(PAHO_BUILD_STATIC)
    set(_PAHO_MQTT_C_LIB_NAME ${_PAHO_MQTT_C_LIB_NAME}-static)
endif()
find_package(eclipse-paho-mqtt-c REQUIRED)
find_package(OpenSSL REQUIRED)
add_definitions(-DLINUX -std=c++11)
add_executable(serial2mqtt)
...

Then the correct way to build paho-mqtt-c with the expected flavor is

cd paho.mqtt.c && cmake -DPAHO_BUILD_STATIC=true -DPAHO_WITH_SSL=true && make && cd ..

I mae some additional tests such as installing the lib paho-mqtt-c, so I hope it does not have fixed some issues without me knowing exactly what changed.

@vortex314
Copy link
Owner

Thanks a lot for your help.
Will you do a pull request ?

@Gagns4395
Copy link
Contributor

This is the first time I involve myself in such open source project. Although I know enough GIT to be able to clone/commit, I'm not yet familiar with pull-request.
So please give me time to learn.
In addition, I must verify that what I recommend is sufficient, by testing it live with my Arduino Mega.

I was looking for such a solution on google, and was surprised that there is not a lot people interrested in that use-case.

@Gagns4395
Copy link
Contributor

@vortex314 as I thought, the fix is not sufficient. I tested on a fresh computer, and there are many actions that can be done to fix the build.
Some are really shortcuts to pure Linux binary format.
However I think that you wanted to have something portable to other platforms. And that becomes a bit more tricky.

Let me investigate and come back to you.

@vortex314
Copy link
Owner

@Gagns4395 thanks already for your effort !

@Gagns4395
Copy link
Contributor

@vortex314 please find my pull-request #62

@chairmanfaust
Copy link
Author

chairmanfaust commented Dec 12, 2024

Hey its been a long time since i've had a chance to look at this project, my goal is to connect my meshtastic station g2 esp32 device to my raspberry pi mosquitto mqtt server via usb/serial instead of wifi which is unreliable. I was able to progress further in the build but failed on the final 'make' step, see below:

mqtt@mqtt:~/serial2mqtt/build $ make
[  8%] Building CXX object CMakeFiles/serial2mqtt.dir/src/Serial2Mqtt.cpp.o
[ 16%] Building CXX object CMakeFiles/serial2mqtt.dir/src/LogFile.cpp.o
[ 25%] Building CXX object CMakeFiles/serial2mqtt.dir/src/Sys.cpp.o
[ 33%] Building CXX object CMakeFiles/serial2mqtt.dir/src/Timer.cpp.o
[ 41%] Building CXX object CMakeFiles/serial2mqtt.dir/src/main.cpp.o
[ 50%] Building CXX object CMakeFiles/serial2mqtt.dir/src/Config.cpp.o
[ 58%] Building CXX object CMakeFiles/serial2mqtt.dir/src/Bytes.cpp.o
[ 66%] Building CXX object CMakeFiles/serial2mqtt.dir/src/Log.cpp.o
/home/mqtt/serial2mqtt/src/Log.cpp: In member function ‘void Log::log(char, const char*, uint32_t, const char*, const char*, ...)’:
/home/mqtt/serial2mqtt/src/Log.cpp:157:24: error: ‘pthread_self’ was not declared in this scope; did you mean ‘pthread_t’?
  157 |     pthread_getname_np(pthread_self(), _application, sizeof(_application));
      |                        ^~~~~~~~~~~~
      |                        pthread_t
/home/mqtt/serial2mqtt/src/Log.cpp:157:5: error: ‘pthread_getname_np’ was not declared in this scope
  157 |     pthread_getname_np(pthread_self(), _application, sizeof(_application));
      |     ^~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/serial2mqtt.dir/build.make:174: CMakeFiles/serial2mqtt.dir/src/Log.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/serial2mqtt.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants