0

I'm trying to build some 3rd party code and link it against our own private version of STLPort, their code uses CMake and I'm new to it.

I'm able to get the compile to work against our STLPort includes but I cannot stop the linker from linking in libstdc++. I've tried:

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib")
list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_LIBRARIES stdc++)

but no luck.

Amazon Linux AMI (based on RHEL 5.x), CMake 2.8.12.

Suggestions/pointers would be greatly appreciated.

Thanks.

Mike Summers
  • 2,139
  • 3
  • 27
  • 57
  • 1
    You can try a [`CMAKE_USER_MAKE_RULES_OVERRIDE`](https://cmake.org/cmake/help/latest/variable/CMAKE_USER_MAKE_RULES_OVERRIDE.html) script. There you can modify `CMAKE_CXX_IMPLICIT_LINK_LIBRARIES` before it's cached in `CMakeCXXCompiler.cmake`. See [here](http://stackoverflow.com/questions/28732209/change-default-value-of-cmake-cxx-flags-debug-and-friends-in-cmake) for an example. – Florian Sep 14 '16 at 14:57
  • This is pilot error. As I allude to below the CMake files are large and there was a hidden/masked error in the STLPort definition that caused problems far away from the definition. `set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib")` is all that's required – Mike Summers Sep 14 '16 at 16:25

1 Answers1

1

I believe there is more logic in your build scripts.

The following CMakeLists.txt:

cmake_minimum_required (VERSION 2.6)
project (Test)
add_executable(Test test.cpp)

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib")
list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_LIBRARIES stdc++)

for test.cpp:

int main()
{
        return 0;
}

produces expected linker warning:

/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400144

What means that my binary was not linked against stdlib.

I believe you should provide more details about your build procedure.

woockashek
  • 1,588
  • 10
  • 25
  • Yes, the build scripts are hundreds of lines long spread across multiple sub directories and are pre-processed with a bash script... a bit too much for SO :-) – Mike Summers Sep 14 '16 at 15:30
  • I suspect that those variables are just overwritten by some other script. Try grep on sources for CMAKE_EXE_LINKER_FLAGS and CMAKE_CXX_IMPLICIT_LINK_LIBRARIES – woockashek Sep 14 '16 at 16:14