1

I have a project in C++, Ubuntu, Linux 64. If the binary is build it with make, generated from cmake. based on CMakeLists.txt yelds a binary of ~720Kb, while code::blocks yields 525Kb binary. My question is why ?

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
PROJECT(WHATEVER)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS "-std=c++0x -Wall -fexceptions -fpermissive -D__USE_MISC")
ADD_EXECUTABLE(mybinary 
                    file1.cpp
                    file2.cpp)

include_directories (.../include)
link_directories(../lib/)
TARGET_LINK_LIBRARIES(mybinary pthread dl ${CMAKE_CURRENT_LIST_DIR}/../lib/somelib.a)
SET(EXECUTABLE_OUTPUT_PATH ../bin)

This yields a binary of: 721Kb, though a Code::Blocks project having same files, same compiler settings, same libraries code::blocks Output build:

Code::blocks

Cleaned "mybinary - Release"

-------------- Build: Release in mybinary (compiler: GNU GCC Compiler)---------------

g++ -std=c++0x -Wall -fexceptions -fpermissive -D__USE_MISC -I../include -c /home/user/project/file1.cpp -o obj/Release/home/user/project/file1.o
g++ -std=c++0x -Wall -fexceptions -fpermissive -D__USE_MISC -I../include -c /home/user/project/file2.cpp -o obj/Release/home/user/project/file2.o
g++  -o ../bin2/mybinary obj/Release/home/user/project/file1.o obj/Release/home/user/project/file2.o -lpthread -ldl ../lib/somelib.a
Output file is ../bin2/mybinary with size 504.17 KB
Process terminated with status 0 (0 minute(s), 17 second(s))
0 error(s), 0 warning(s) (0 minute(s), 17 second(s))
 

Yields a binary of: 504Kb

Thank you

Community
  • 1
  • 1
Ion Ion
  • 51
  • 3

0 Answers0