vectorgrp / XCPlite

Simple implementation of the ASAM XCP on Ethernet protocol
MIT License
171 stars 93 forks source link

C only example needs "math.h" support for cmake #5

Closed brenkem closed 3 years ago

brenkem commented 3 years ago

For a C only demonstration (like [1]), you need to add "math.h" support into CMAKE project file, see [2]. Otherwise compiling will end up like [0].

[0]:

Scanning dependencies of target xcpLite
[ 10%] Building C object CMakeFiles/xcpLite.dir/main.c.o
[ 20%] Building C object CMakeFiles/xcpLite.dir/ecu.c.o
[ 30%] Building C object CMakeFiles/xcpLite.dir/udpserver.c.o
[ 40%] Building C object CMakeFiles/xcpLite.dir/udp.c.o
[ 50%] Building C object CMakeFiles/xcpLite.dir/xcpAppl.c.o
[ 60%] Building C object CMakeFiles/xcpLite.dir/xcpLite.c.o
[ 70%] Building C object CMakeFiles/xcpLite.dir/A2L.c.o
[ 80%] Building C object CMakeFiles/xcpLite.dir/xcpSlave.c.o
[ 90%] Building C object CMakeFiles/xcpLite.dir/clock.c.o
[100%] Linking C executable xcpLite
CMakeFiles/xcpLite.dir/ecu.c.o: In Funktion »ecuCyclic«:
/home/brenkem/git/XCPlite/ecu.c:307: Warnung: undefinierter Verweis auf »sin«
/home/brenkem/git/XCPlite/ecu.c:308: Warnung: undefinierter Verweis auf »sin«
/home/brenkem/git/XCPlite/ecu.c:309: Warnung: undefinierter Verweis auf »sin«
/home/brenkem/git/XCPlite/ecu.c:310: Warnung: undefinierter Verweis auf »sin«
/home/brenkem/git/XCPlite/ecu.c:311: Warnung: undefinierter Verweis auf »sin«
CMakeFiles/xcpLite.dir/ecu.c.o:/home/brenkem/git/XCPlite/ecu.c:312: Warnung: weitere undefinierte Verweise auf »sin« folgen
collect2: error: ld returned 1 exit status
CMakeFiles/xcpLite.dir/build.make:302: recipe for target 'xcpLite' failed
make[2]: *** [xcpLite] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/xcpLite.dir/all' failed
make[1]: *** [CMakeFiles/xcpLite.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

[1]:

$ diff -us main.cpp main.c
--- main.cpp    2021-06-23 11:59:37.971809677 +0200
+++ main.c  2021-06-23 13:32:01.755285006 +0200
@@ -1,6 +1,6 @@
 /*----------------------------------------------------------------------------
 | File:
-|   main.cpp
+|   main.c
 |
 | Description:
 |   Demo main for XCP on Ethernet (UDP) demo
@@ -49,11 +49,10 @@
         A2lHeader();
     }
     ecuCreateA2lDescription();
-    ecuppCreateA2lDescription();
     A2lCreateParameterWithLimits(gDebugLevel, "Console output verbosity", "", 0, 4);
     A2lCreateParameterWithLimits(gFlushCycleMs, "DAQ flush cycle time, 0 = off", "", 0, 1000);
     A2lClose();
@@ -80,13 +79,13 @@
- // C++ main
+ // C main
 int main(int argc, char* argv[])
@@ -255,13 +254,9 @@
 #endif

     // C demo
    // Initialize ECU demo task (C) 
     ecuInit();
-        
-    // C++ demo
-    // Initialize ECU demo tasks (C++) 
-    ecuppInit();
-    
+

 #ifdef _LINUX

@@ -271,10 +266,7 @@
         createA2L(p);
     }

-    // Demo threads
-    pthread_t t3;
-    int a3 = 0;
-    pthread_create(&t3, NULL, ecuppTask, (void*)&a3);
+    // Demo thread
     pthread_t t2;
     int a2 = 0;
     pthread_create(&t2, NULL, ecuTask, (void*)&a2);
@@ -293,12 +285,11 @@

 #ifndef XCPSIM_SINGLE_THREAD_SLAVE
     pthread_cancel(t1);
 #endif
     pthread_cancel(t2);
-    pthread_cancel(t3);

 #endif // _LINUX
 #ifdef _WIN
@@ -312,7 +303,6 @@

     // Demo threads
     std::thread t2([]() { ecuTask(0); });
-    std::thread t3([]() { ecuppTask(0); });

[2]:

$ git diff CMakeLists.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7515d4b..91f54c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.1.0)
 project(xcpLite)

-set(SOURCES main.cpp ecupp.cpp ecu.c udpserver.c udp.c xcpAppl.c xcpLite.c A2L.c xcpSlave.c clock.c)
+set(SOURCES main.c ecu.c udpserver.c udp.c xcpAppl.c xcpLite.c A2L.c xcpSlave.c clock.c)
 set(CMAKE_BUILD_TYPE Debug)

 add_executable(xcpLite ${SOURCES})
@@ -9,4 +9,4 @@ add_executable(xcpLite ${SOURCES})
 set(THREADS_PREFER_PTHREAD_FLAG ON)
 find_package(Threads REQUIRED)
 target_link_libraries(xcpLite PRIVATE Threads::Threads)
-
+target_link_libraries(xcpLite PRIVATE m)