package/openpowerlink: use pcap-config to fix static linking with libpcap
PATCH 1/1 package/openpowerlink: use pcap-config to fix static linking with libpcap
When linking demo_mn_console statically with pcap, the CMake build system forget to link with other libraries linked with libpcap (-lnl-genl-3 -lnl-3 -ldbus-1 -pthread).
[100%] Linking C executable demo_mn_console
lib64/libpcap.a(pcap-linux.o): In function nl80211_init': pcap-linux.c:(.text+0x41e): undefined reference tonl_socket_alloc'
To fix this, the build system could use pcap-config:
pcap-config --libs --static
-L/path/to/sysroot/usr/lib -lpcap -L/path/to/sysroot/usr/lib/.libs -lnl-genl-3 -lnl-3 -L/path/to/sysroot/usr/lib -ldbus-1 -pthread
Also don't use getopt() from contrib directory to avoid a clash with libc definition.
Fixes:
http://autobuild.buildroot.net/results/f43/f437d09ac6c689c911e1885b95da33b692f2cb3c
http://autobuild.buildroot.net/results/385/3859dc0f4de7e3284a96d5841f040f69f71842df
https://github.com/OpenAutomationTechnologies/openPOWERLINK_V2/issues/187
--- ...04-FIX-use-contrib-getopt-only-on-Windows.patch | 102 +++++++++++++ ...p-config-to-fix-static-linking-with-libpc.patch | 166 +++++++++++++++++++++ package/openpowerlink/openpowerlink.mk | 6 +- 3 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 package/openpowerlink/0004-FIX-use-contrib-getopt-only-on-Windows.patch create mode 100644 package/openpowerlink/0005-FIX-use-pcap-config-to-fix-static-linking-with-libpc.patch
package/openpowerlink/0004-FIX-use-contrib-getopt-only-on-Windows.patch new file +102 -0
@@ -0,0 +1,102 @@ +From d05273e65657d82e44fb7bd91a8fba0ba990ff2c Mon Sep 17 00:00:00 2001 +From: Romain Naour <[email protected]> +Date: Sat, 27 May 2017 23:51:41 +0200 +Subject: [PATCH] [FIX] use contrib getopt() only on Windows + +Otherwise, contrib getopt will clash with the one from the libc when +building statically. + +lib64/libc.a(getopt.os):(.data+0x8): multiple definition of `optind' +CMakeFiles/demo_mn_console.dir/__/__/contrib/getopt/getopt.c.o:(.data+0x8): first defined here +lib64/libc.a(getopt.os):(.data+0x4): multiple definition of `opterr' +CMakeFiles/demo_mn_console.dir/__/__/contrib/getopt/getopt.c.o:(.data+0xc): first defined here +/lib64/libc.a(getopt.os): In function `__GI_getopt': +getopt.c:(.text+0x76e): multiple definition of `getopt' + +Signed-off-by: Romain Naour <[email protected]> +--- + apps/demo_cn_console/CMakeLists.txt | 2 +- + apps/demo_cn_console/src/main.c | 6 ++++++ + apps/demo_mn_console/CMakeLists.txt | 2 +- + apps/demo_mn_console/src/main.c | 6 ++++++ + 4 files changed, 14 insertions(+), 2 deletions(-) + +diff --git a/apps/demo_cn_console/CMakeLists.txt b/apps/demo_cn_console/CMakeLists.txt +index a3a80bb..5733213 100644 +--- a/apps/demo_cn_console/CMakeLists.txt ++++ b/apps/demo_cn_console/CMakeLists.txt +@@ -61,7 +61,6 @@ SET(DEMO_SOURCES + ${COMMON_SOURCE_DIR}/eventlog/eventlog.c + ${COMMON_SOURCE_DIR}/eventlog/eventlogstring.c + ${CONTRIB_SOURCE_DIR}/console/printlog.c +- ${CONTRIB_SOURCE_DIR}/getopt/getopt.c + ) + + INCLUDE_DIRECTORIES( +@@ -114,6 +113,7 @@ ENDIF (CFG_KERNEL_STACK_DIRECTLINK) + IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + include(linux.cmake) + ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Windows") ++ SET(DEMO_SOURCES ${DEMO_SOURCES} ${CONTRIB_SOURCE_DIR}/getopt/getopt.c) + include (windows.cmake) + ELSE() + MESSAGE(FATAL_ERROR "System ${CMAKE_SYSTEM_NAME} is not supported!") +diff --git a/apps/demo_cn_console/src/main.c b/apps/demo_cn_console/src/main.c +index c630586..9406473 100644 +--- a/apps/demo_cn_console/src/main.c ++++ b/apps/demo_cn_console/src/main.c +@@ -50,7 +50,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include <system/system.h> + #include <obdcreate/obdcreate.h> ++ ++#if (TARGET_SYSTEM == _WIN32_) + #include <getopt/getopt.h> ++#else ++#include <unistd.h> ++#endif ++ + #include <console/console.h> + #include <eventlog/eventlog.h> + +diff --git a/apps/demo_mn_console/CMakeLists.txt b/apps/demo_mn_console/CMakeLists.txt +index 9c3378c..a81c4b3 100644 +--- a/apps/demo_mn_console/CMakeLists.txt ++++ b/apps/demo_mn_console/CMakeLists.txt +@@ -67,7 +67,6 @@ SET(DEMO_SOURCES + ${COMMON_SOURCE_DIR}/eventlog/eventlog.c + ${COMMON_SOURCE_DIR}/eventlog/eventlogstring.c + ${CONTRIB_SOURCE_DIR}/console/printlog.c +- ${CONTRIB_SOURCE_DIR}/getopt/getopt.c + ) + + INCLUDE_DIRECTORIES( +@@ -129,6 +128,7 @@ ENDIF() + IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + include(linux.cmake) + ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Windows") ++ SET(DEMO_SOURCES ${DEMO_SOURCES} ${CONTRIB_SOURCE_DIR}/getopt/getopt.c) + include (windows.cmake) + ELSE() + MESSAGE(FATAL_ERROR "System ${CMAKE_SYSTEM_NAME} is not supported!") +diff --git a/apps/demo_mn_console/src/main.c b/apps/demo_mn_console/src/main.c +index 12d9be0..194e446 100644 +--- a/apps/demo_mn_console/src/main.c ++++ b/apps/demo_mn_console/src/main.c +@@ -50,7 +50,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + #include <system/system.h> + #include <obdcreate/obdcreate.h> ++ ++#if (TARGET_SYSTEM == _WIN32_) + #include <getopt/getopt.h> ++#else ++#include <unistd.h> ++#endif ++ + #include <console/console.h> + #include <eventlog/eventlog.h> + +-- +2.9.4 +
package/openpowerlink/0005-FIX-use-pcap-config-to-fix-static-linking-with-libpc.patch new file +166 -0
166 lines not on this page · raw message
package/openpowerlink/openpowerlink.mk +4 -2
@@ -40,7 +40,8 @@ OPENPOWERLINK_CONF_OPTS += \ -DCFG_COMPILE_LIB_CN=$(OPENPOWERLINK_CN_ONOFF) \ -DCFG_COMPILE_LIB_CNAPP_USERINTF=OFF \ -DCFG_COMPILE_LIB_CNAPP_KERNELINTF=OFF \ - -DCFG_COMPILE_LIB_CNDRV_PCAP=OFF + -DCFG_COMPILE_LIB_CNDRV_PCAP=OFF \ + -DPCAP_CONFIG="$(STAGING_DIR)/usr/bin/pcap-config" else ifeq ($(BR2_PACKAGE_OPENPOWERLINK_STACK_USERSPACE_DAEMON_LIB),y) OPENPOWERLINK_DEPENDENCIES += libpcap OPENPOWERLINK_CONF_OPTS += \
@@ -52,7 +53,8 @@ OPENPOWERLINK_CONF_OPTS += \ -DCFG_COMPILE_LIB_CN=OFF \ -DCFG_COMPILE_LIB_CNAPP_USERINTF=$(OPENPOWERLINK_CN_ONOFF) \ -DCFG_COMPILE_LIB_CNAPP_KERNELINTF=OFF \ - -DCFG_COMPILE_LIB_CNDRV_PCAP=$(OPENPOWERLINK_CN_ONOFF) + -DCFG_COMPILE_LIB_CNDRV_PCAP=$(OPENPOWERLINK_CN_ONOFF) \ + -DPCAP_CONFIG="$(STAGING_DIR)/usr/bin/pcap-config" else ifeq ($(BR2_PACKAGE_OPENPOWERLINK_STACK_KERNEL_STACK_LIB),y) OPENPOWERLINK_CONF_OPTS += \ -DCFG_COMPILE_LIB_MN=OFF \
Signature · 1 line
2.9.4
PATCH 1/1 package/openpowerlink: use pcap-config to fix static linking with libpcap
Am Sun, 28 May 2017 00:51:19 +0200 schrieb Romain Naour:
Quoted 13 lines
When linking
demo_mn_consolestatically with pcap, the CMake build system forget to link with other libraries linked with libpcap (-lnl-genl-3 -lnl-3 -ldbus-1 -pthread).[100%] Linking C executable
demo_mn_consolelib64/libpcap.a(pcap-linux.o): In functionnl80211_init':
pcap-linux.c:(.text+0x41e): undefined referencetonl_socket_alloc'To fix this, the build system could use pcap-config:
pcap-config --libs --static -L/path/to/sysroot/usr/lib -lpcap(quoted diff) +0
-2-L/path/to/sysroot/usr/lib/.libs -lnl-genl-3 -lnl-3 -L/path/to/sysroot/usr/lib -ldbus-1 -pthread
Quoted 5 lines
Also don't use
getopt()from contrib directory to avoid a clash with libc definition.
f437d09ac6c689c911e1885b95da33b692f2cb3c
Quoted 1 line
results/385/3859dc0f4de7e3284a96d5841f040f69f71842df
issues/187
Quoted 3 lines
Signed-off-by: Romain Naour
<[email protected]>
(compile-tested using http://autobuild.buildroot.net/results/f43/
f437d09ac6c689c911e1885b95da33b692f2cb3c/ )
Thomas Petazzoni
AppliedPATCH 1/1 package/openpowerlink: use pcap-config to fix static linking with libpcap
In reply to Romain NaourHello,
Quoted 20 lines · Romain Naour
When linking
demo_mn_consolestatically with pcap, the CMake build system forget to link with other libraries linked with libpcap (-lnl-genl-3 -lnl-3 -ldbus-1 -pthread).[100%] Linking C executable
demo_mn_console
lib64/libpcap.a(pcap-linux.o): In functionnl80211_init': pcap-linux.c:(.text+0x41e): undefined referencetonl_socket_alloc'To fix this, the build system could use pcap-config:
pcap-config --libs --static(quoted diff) +0
-2-L/path/to/sysroot/usr/lib -lpcap -L/path/to/sysroot/usr/lib/.libs -lnl-genl-3 -lnl-3 -L/path/to/sysroot/usr/lib -ldbus-1 -pthreadAlso don't use
getopt()from contrib directory to avoid a clash with libc definition.Fixes:
http://autobuild.buildroot.net/results/f43/f437d09ac6c689c911e1885b95da33b692f2cb3c
http://autobuild.buildroot.net/results/385/3859dc0f4de7e3284a96d5841f040f69f71842df
https://github.com/OpenAutomationTechnologies/openPOWERLINK_V2/issues/187
Quoted 8 lines
Signed-off-by Romain Naour <[email protected]>--- ...04-FIX-use-contrib-getopt-only-on-Windows.patch | 102 +++++++++++++ ...p-config-to-fix-static-linking-with-libpc.patch | 166 +++++++++++++++++++++ package/openpowerlink/openpowerlink.mk | 6 +- 3 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 package/openpowerlink/0004-FIX-use-contrib-getopt-only-on-Windows.patch create mode 100644 package/openpowerlink/0005-FIX-use-pcap-config-to-fix-static-linking-with-libpc.patch
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com