0

I am working on a C project. I am using cmake as build generator. I have set the below things in my cmakelists.txt just below project() command

set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_ASM_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_C_OUTPUT_EXTENSION .o)
set(CMAKE_ASM_OUTPUT_EXTENSION .o)

I have files with .c extensions and assembly files with .s extensions. During compilation, i see that files are created with .obj extension(file.c --> file.obj) my expectation is with .o extension(file.c --> file.o). anything i have to set apart from the above commands ?

  • 1
    `.obj` if often used in Windows while `.o` is often used in Posix. I would use the default extensions instead of setting them explicitly. – Ted Lyngmo Mar 15 '21 at 19:12
  • 2
    i am building software for embedded system(cross compiling). i have some pre defined object files with .o extension. it could be helpful if other files are also generated with .o extension – Deepan Muthusamy Mar 15 '21 at 19:19
  • 1
    I see. Have you set [`CMAKE_SYSTEM_NAME`](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html#variable:CMAKE_SYSTEM_NAME)? I would expect all files to get the proper extensions by default when using CMake, but I could be wrong. – Ted Lyngmo Mar 15 '21 at 19:24
  • yes.. i have set.. #Specify the environment -- embedded set(CMAKE_SYSTEM_NAME "Generic") #Specifiy the Architecture -- PowerPC set(CMAKE_SYSTEM_PROCESSOR "ppc") – Deepan Muthusamy Mar 15 '21 at 19:28
  • What if you specify the actual OS name instead of `Generic`? – Ted Lyngmo Mar 15 '21 at 19:30
  • The os used here is "tresos". If i use this, i am getting error "system is unknown to cmake" – Deepan Muthusamy Mar 15 '21 at 19:35
  • I see. Perhaps you could ask Elektrobit for advice. They probably have some ideas how to set it up properly. – Ted Lyngmo Mar 15 '21 at 19:44
  • i am getting expected result by setting set(CMAKE_SYSTEM_NAME "Linux") and executable also getting generated. will it be a problem ? – Deepan Muthusamy Mar 15 '21 at 19:53
  • 1
    If the rest of the cross compiling options are ok it could work. You could try `Posix` too. The EB tresos OS:es seems to be based on `Posix` (just like Linux). – Ted Lyngmo Mar 15 '21 at 20:04
  • 1
    ok.. thank you @TedLyngmo – Deepan Muthusamy Mar 16 '21 at 04:53

0 Answers0