COVESA / dlt-daemon

Diagnostic Log and Trace.
https://covesa.github.io/dlt-daemon/
Mozilla Public License 2.0
357 stars 286 forks source link

Building for QNX #336

Closed boraborosa closed 2 years ago

boraborosa commented 2 years ago

Hi,

While I was trying to crosscompile (Ubuntu as host and QNX as target), I got "-lrt not found" error and solved that by changing corresponding CMakeLists.txt files. Similarly, I got -lsocket not found error.

I have changed rt with mq and also kept the socket lib. A build option for this would be nice (or perhaps checking the compiler if it is qcc).

Below you can see the temporary changes I have applied to be able to build for QNX.

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 3ceae3c..ae41dfb 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -74,7 +74,8 @@ CHECK_FUNCTION_EXISTS( strstr HAVE_FUNC_STRSTR)
 CHECK_FUNCTION_EXISTS( strtol HAVE_FUNC_STRTOL)

 # Message queue
-find_library(RT_LIBRARY rt)
+#find_library(RT_LIBRARY rt)
+find_library(RT_LIBRARY mq)
 if(RT_LIBRARY)
   include(CheckLibraryExists)
   CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_open mqueue.h HAVE_FUNC_MQOPEN)
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index adddee3..0c6cf64 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -52,6 +52,8 @@ else()
     set(RT_LIBRARY "")
     set(SOCKET_LIBRARY socket)
 endif()
+set(RT_LIBRARY mq)
+set(SOCKET_LIBRARY socket)

 if(WITH_UDP_CONNECTION)
     include_directories(${PROJECT_SOURCE_DIR}/src/daemon/udp_connection)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index fb5a2a4..ba70930 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -37,6 +37,9 @@ else()
     set(SOCKET_LIBRARY socket)
 endif()

+set(RT_LIBRARY mq)
+set(SOCKET_LIBRARY socket)
+
 if(HAVE_FUNC_PTHREAD_SETNAME_NP)
     add_definitions(-DDLT_USE_PTHREAD_SETNAME_NP)
     message(STATUS "Using pthread_setname_np API to set thread name")

Thanks :)

ssugiura commented 2 years ago

@boraborosa I suppose these are already handled by comparing against ${CMAKE_SYSTEM_NAME}, e.g. https://github.com/GENIVI/dlt-daemon/blob/master/src/daemon/CMakeLists.txt#L51

With regards to mq library, this is only required for alternative implementation of message queue. http://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/m/mq_open.html Simple solution we can have is to introduce new cmake option "WITH_QNX_MQUEUE" (=ON to use traditional implementation mqueue) and link mq is this set to OFF (use alternative).

If the idea is good, please raise a PR. Thank you in advance!

boraborosa commented 2 years ago

Thanks @ssugiura for the quick response.

You are right, CMAKE_SYSTEM_NAME option works.

This was my bad because I assumed cmake would change CMAKE_SYSTEM_NAME to QNX when I used qcc, similar to behaviour on https://github.com/GENIVI/dlt-daemon/blob/master/CMakeLists.txt#L161.

I believe mq option is not necessary at this time.

ghost commented 9 months ago

Hi,

While I was trying to crosscompile (Ubuntu as host and QNX as target), I got "-lrt not found" error and solved that by changing corresponding CMakeLists.txt files. Similarly, I got -lsocket not found error.

I have changed rt with mq and also kept the socket lib. A build option for this would be nice (or perhaps checking the compiler if it is qcc).

Below you can see the temporary changes I have applied to be able to build for QNX.

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 3ceae3c..ae41dfb 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -74,7 +74,8 @@ CHECK_FUNCTION_EXISTS( strstr HAVE_FUNC_STRSTR)
 CHECK_FUNCTION_EXISTS( strtol HAVE_FUNC_STRTOL)

 # Message queue
-find_library(RT_LIBRARY rt)
+#find_library(RT_LIBRARY rt)
+find_library(RT_LIBRARY mq)
 if(RT_LIBRARY)
   include(CheckLibraryExists)
   CHECK_LIBRARY_EXISTS( ${RT_LIBRARY} mq_open mqueue.h HAVE_FUNC_MQOPEN)
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index adddee3..0c6cf64 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -52,6 +52,8 @@ else()
     set(RT_LIBRARY "")
     set(SOCKET_LIBRARY socket)
 endif()
+set(RT_LIBRARY mq)
+set(SOCKET_LIBRARY socket)

 if(WITH_UDP_CONNECTION)
     include_directories(${PROJECT_SOURCE_DIR}/src/daemon/udp_connection)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index fb5a2a4..ba70930 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -37,6 +37,9 @@ else()
     set(SOCKET_LIBRARY socket)
 endif()

+set(RT_LIBRARY mq)
+set(SOCKET_LIBRARY socket)
+
 if(HAVE_FUNC_PTHREAD_SETNAME_NP)
     add_definitions(-DDLT_USE_PTHREAD_SETNAME_NP)
     message(STATUS "Using pthread_setname_np API to set thread name")

Thanks :)

Can you share example sample CPP code to use DLT Logging inside a function called from main function in compiled in QNX environment. ??

ghost commented 9 months ago

@boraborosa I suppose these are already handled by comparing against ${CMAKE_SYSTEM_NAME}, e.g. https://github.com/GENIVI/dlt-daemon/blob/master/src/daemon/CMakeLists.txt#L51

With regards to mq library, this is only required for alternative implementation of message queue. http://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/m/mq_open.html Simple solution we can have is to introduce new cmake option "WITH_QNX_MQUEUE" (=ON to use traditional implementation mqueue) and link mq is this set to OFF (use alternative).

If the idea is good, please raise a PR. Thank you in advance!

Can you share example sample CPP code to use DLT Logging inside a function called from main function in compiled in QNX environment. ??