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

Static Compilation setup and Seed Fixing #5

Open
kuldeepmeel opened this issue May 4, 2020 · 3 comments
Open

Static Compilation setup and Seed Fixing #5

kuldeepmeel opened this issue May 4, 2020 · 3 comments

Comments

@kuldeepmeel
Copy link

Hi Zayd:

I was wondering if you can setup the instructions for static compilation and @msoos added the option for a seed to spur for reproducibility (Here is the commit: meelgroup@1ebc536)

The pull request seemed messy, so perhaps its easy for you to just integrate the changes.

--
Kuldeep

@kuldeepmeel
Copy link
Author

Oh well.. I am really late to this. Mate already raised the pull request.

@ZaydH
Copy link
Owner

ZaydH commented May 6, 2020

Hi Kuldeep,

I hope all is well with you, your family, and your students during this crisis.

Yes @msoos's pull request was integrated and a new version release. I do not believe that pull request included static compilation. Do you still want that added as well?

Regards,
Zayd

@msoos
Copy link
Contributor

msoos commented May 6, 2020

Hey,

Yeah, I didn't fix the static compilation indeed. Do you know how to fix it? I have been playing, but the below doesn't seem to work, though perhaps it's close:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b7ee5a8..e9687dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,16 +9,46 @@ project (SPUR)
 # -fno-omit-frame-pointer   Preserve the frame pointer for use with perf
 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall")
 
 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -O3 -DNDEBUG -Wall")
 
 set(CMAKE_CXX_FLAGS_PROFILING "${CMAKE_CXX_FLAGS_PROFILING} -std=c++11 -O3 -g
     -DNDEBUG -Wall -fno-omit-frame-pointer")
 
+option(STATICCOMPILE "Compile to static executable" OFF)
+if (STATICCOMPILE)
+    set(BUILD_SHARED_LIBS OFF)
+endif()
+
+if ((${CMAKE_SYSTEM_NAME} MATCHES "Linux") OR (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
+    if(NOT BUILD_SHARED_LIBS)
+        MESSAGE(STATUS "Compiling for static library use")
+        if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+            set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -Wl,--whole-archive -ldl -lpthread -Wl,--no-whole-archive -static ")
+        endif()
+
+        SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+
+        # removing -rdynamic that's automatically added
+        foreach (language CXX C)
+            set(VAR_TO_MODIFY "CMAKE_SHARED_LIBRARY_LINK_${language}_FLAGS")
+            string(REGEX REPLACE "(^| )-rdynamic($| )"
+                                 " "
+                                 replacement
+                                 "${${VAR_TO_MODIFY}}")
+            #message("Original (${VAR_TO_MODIFY}) is ${${VAR_TO_MODIFY}} replacement is ${replacement}")
+            set(${VAR_TO_MODIFY} "${replacement}" CACHE STRING "Default flags for ${build_config} configuration" FORCE)
+        endforeach()
+    else()
+        add_definitions(-DBOOST_TEST_DYN_LINK)
+        MESSAGE(STATUS "Compiling for dynamic library use")
+    endif()
+endif()
+
 IF(UNIX)
   IF(APPLE)
     include_directories(/opt/local/include)
   ELSE(APPLE)
 
 
   ENDIF(APPLE)
 ELSE(UNIX)
@@ -27,9 +57,12 @@ ENDIF(UNIX)
 
 # GNU Multiprecision library
 find_library(GMP_LIB gmp)
 find_library(GMPXX_LIB gmpxx)
 
 add_subdirectory(src)
 
 add_executable (spur src/main.cpp)
+set_target_properties(spur PROPERTIES
+        RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}
+        INSTALL_RPATH_USE_LINK_PATH TRUE)
 target_link_libraries (spur libSpur ${GMP_LIB} ${GMPXX_LIB})

Since I don't have the static gmp and gmpxx libraries, I am getting:

soos@vvv-dejavu:build$ cmake -DSTATICCOMPILE=ON ..  
-- The C compiler identification is GNU 9.2.1
-- The CXX compiler identification is GNU 9.2.1
-- Check for working C compiler: /usr/lib/ccache/bin/cc
-- Check for working C compiler: /usr/lib/ccache/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/lib/ccache/bin/c++
-- Check for working CXX compiler: /usr/lib/ccache/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiling for static library use
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
GMPXX_LIB
    linked by target "spur" in directory /home/soos/development/sat_solvers/spur
GMP_LIB
    linked by target "spur" in directory /home/soos/development/sat_solvers/spur

-- Configuring incomplete, errors occurred!
See also "/home/soos/development/sat_solvers/spur/build/CMakeFiles/CMakeOutput.log".

Perhaps the only way to fix this is to install them statically as well? Perhaps you or Kuldeep know best how to do this, I'll leave this to the experts.

Cheers,

Mate

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

3 participants