Closed Totktonada closed 2 years ago
Got another problem before this one:
$ tarantoolctl rocks make
<...>
[ 41%] Linking C executable mosquitto_rr
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: CMakeFiles/mosquitto_rr.dir/pub_shared.c.o:/home/alex/p/tarantool-meta/mqtt/third_party/mosquitto/client/pub_shared.c:41: multiple definition of `cfg'; CMakeFiles/mosquitto_rr.dir/rr_client.c.o:/home/alex/p/tarantool-meta/mqtt/third_party/mosquitto/client/rr_client.c:50: first defined here
collect2: error: ld returned 1 exit status
The fix from https://github.com/eclipse/mosquitto/issues/1453 resolves the problem. We should update mosquitto to at least 1.6.8.
I verified it this way:
$ git -C third_party/mosquitto diff
diff --git a/client/rr_client.c b/client/rr_client.c
index 5ecd309..37cfbff 100644
--- a/client/rr_client.c
+++ b/client/rr_client.c
@@ -47,7 +47,7 @@ enum rr__state {
static enum rr__state client_state = rr_s_new;
-struct mosq_config cfg;
+extern struct mosq_config cfg;
bool process_messages = true;
int msg_count = 0;
struct mosquitto *mosq = NULL;
The original problem seems to be fixed by the following patch:
diff --git a/mqtt/CMakeLists.txt b/mqtt/CMakeLists.txt
index de85ecd..316ec8e 100644
--- a/mqtt/CMakeLists.txt
+++ b/mqtt/CMakeLists.txt
@@ -20,7 +20,7 @@ add_library(driver SHARED driver.c)
if( DEFINED STATIC_BUILD )
set(CMAKE_C_FLAGS "-ldl -lpthread")
- add_subdirectory(../third_party/mosquitto ../third_party/mosquitto/build)
+ add_subdirectory(../third_party/mosquitto ../third_party/mosquitto/build EXCLUDE_FROM_ALL)
include_directories(../third_party/mosquitto/lib)
if( STATIC_BUILD )
target_link_libraries(driver libmosquitto_static ${LDFLAGS_EX})
The idea is from https://github.com/tarantool/httpng/pull/27.
However the following warning disquiets me:
$ tarantoolctl rocks make
<...>
Warning: unmatched variable STATIC_BUILD
$ STATIC_BUILD=ON tarantoolctl rocks make
<...>
Warning: unmatched variable STATIC_BUILD
Maybe we should build libmosquitto and link it statically into the module by default? Anyway, it would be nice to investigate why the warning appears.
Eliminated the warning and got static build with the next changes.
Hardcode static build in the rock spec:
diff --git a/mqtt-scm-1.rockspec b/mqtt-scm-1.rockspec
index 7a0634e..f2b3dd2 100644
--- a/mqtt-scm-1.rockspec
+++ b/mqtt-scm-1.rockspec
@@ -18,7 +18,7 @@ build = {
CMAKE_BUILD_TYPE="RelWithDebInfo";
TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)";
TARANTOOL_INSTALL_LUADIR="$(LUADIR)";
- STATIC_BUILD="$(STATIC_BUILD)";
+ STATIC_BUILD="ON";
};
platforms = {
macosx = {
Added WITH_PIC
as an option, not just variable (seems related to the CMP0077 policy):
diff --git a/mqtt/CMakeLists.txt b/mqtt/CMakeLists.txt
index de85ecd..15fab02 100644
--- a/mqtt/CMakeLists.txt
+++ b/mqtt/CMakeLists.txt
@@ -4,6 +4,7 @@
option(DOCUMENTATION "Build documentation?" OFF)
option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF)
+option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF)
if( STATIC_BUILD )
set(WITH_STATIC_LIBRARIES ON)