# CMake generating much smaller \*.a files than makefile

**URL:** <https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816>\
**Category:** Code\
**Created:** [September 10, 2020, 3:26pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816 "2020-09-10T15:26:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dehilster](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dehilster/32/821_2.png) [@dehilster](https://discourse.cmake.org/u/dehilster)\
**Post date:** [September 10, 2020, 3:26pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816/1 "2020-09-10T15:26:48Z")

</div>

When converting from makefile to CMake, the resulting file sizes are hugely different.

size with makefile: 266k  
size with cmake: 33K

Here are the files. Any insight would be very helpful!

**Makefile:**

```
LIBOBJ = dir.o io.o libprim.o list.o prim.o sm.o str.o dyn.o u_out.o
TARG	= libprim.a
CC	= g++
CFLAGS	= -g -DLINUX -I../../include/Api -I../include -Wno-write-strings

%.o: %.cpp
	$(CC) $(CFLAGS) -c $< -o $@

all: $(TARG)
$(TARG): $(LIBOBJ)
	ar r $(TARG) $(LIBOBJ)
	ranlib $(TARG)
	cp $(TARG) ../../lib

clean:
	/bin/rm -f $(TARG) *.o

```

**CMakeLists.txt:**

```
include_directories(../../include/Api)
include_directories(../include)

add_definitions( -DLIBPRIM_EXPORTS )
if(WIN32)
  add_definitions( -DMSVC_VERSION=${MSVC_VERSION} -D_CRT_SECURE_NO_WARNINGS )
else()
  add_definitions( -DLINUX -Wno-write-strings)
endif()

add_library(libprim STATIC
    dir.cpp
    io.cpp
    libprim.cpp
    list.cpp
    prim.cpp
    sm.cpp
    str.cpp
    dyn.cpp
    u_out.cpp
)
```

---

<div class="post-metadata">

**Author:** ![dehilster](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dehilster/32/821_2.png) [@dehilster](https://discourse.cmake.org/u/dehilster)\
**Post date:** [September 10, 2020, 3:30pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816/2 "2020-09-10T15:30:16Z")

</div>

Could it be the **ar** and **ranlib**?

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [September 10, 2020, 3:33pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816/3 "2020-09-10T15:33:00Z")

</div>

The Makefile version has the -g flag. Maybe you built the Release version with CMake and the difference is optimization and no debug symbols?

---

<div class="post-metadata">

**Author:** ![dehilster](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dehilster/32/821_2.png) [@dehilster](https://discourse.cmake.org/u/dehilster)\
**Post date:** [September 10, 2020, 3:34pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816/4 "2020-09-10T15:34:53Z")

</div>

I will look into it.

---

<div class="post-metadata">

**Author:** ![dehilster](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dehilster/32/821_2.png) [@dehilster](https://discourse.cmake.org/u/dehilster)\
**Post date:** [September 10, 2020, 3:39pm UTC](https://discourse.cmake.org/t/cmake-generating-much-smaller-a-files-than-makefile/1816/5 "2020-09-10T15:39:40Z")

</div>

That was it! Simply adding set(CMAKE\_BUILD\_TYPE Debug) made it the same size. Thx!
