1

I have the following files

main.cpp:
#include "f.h"

int main(){
    f();
}

f.h:
int f();

f.cpp:
int f(){
    int x=1;
}

First I am compiling f.cpp to an object file: gcc -c f.cpp -O0 and use this object file to compile main.cpp gcc f.o main.cpp.

Performing gdb a.out, info functions shows f(). Executing strip a.out removes it.

I would like to do the same thing using Cmake. I have created the following directory structure with main directories f and main:

f
    build
    src
        f.h
        f.c
        CMakeLists.txt

CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.8)
project(f)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0")
add_library(f OBJECT
    f.cpp
)

main
    build
    src
        main.cpp
        CMakeLists.txt

CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.8)
project(main)
set(CMAKE_BUILD_TYPE Release)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../f/src
         ${CMAKE_CURRENT_SOURCE_DIR}/../../f/build)
add_executable(main
    main.cpp
    $<TARGET_OBJECTS:f>
)

I ran cmake and make first in f, after that in main. I have got the main executable with f(). However issuing strip main, or even strip -s main does not remove the symbolic name f().

  1. Why does not remove strip the symbolic names if I use Cmake?
  2. Is there a way to compile my files in the same way (object file from f.cpp and after that main executable) using Cmake, and remove symbolic names from the executable?
robert
  • 3,539
  • 3
  • 35
  • 56

1 Answers1

0

I've never used strip, but according to this article you can achieve the same effect with the -s compiler option. You could try adding -s to CMAKE_CXX_FLAGS_RELEASE. It appears they may not be entirely equivalent though.

Community
  • 1
  • 1
RjOllos
  • 2,900
  • 1
  • 19
  • 29