Help on setting up CMake project

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help on setting up CMake project

2,371 Views
AgustinOrdonez
Contributor I

Hello, I am trying to make a CMake project to use Clion as an IDE.I have a LPC845 which is cortex-m0,  I've found this CMakeLists.txt for generic cortex CPUs but I cannot make it work.
As linker script what I did is merging all .ld files that mcuexpresso generated on Debug directory. And added every "TODO" except the "definition" one which I don't know how to fill. When I try to build the target I get a huge error which says

CMakeFiles/3.26.4/CompilerIdCXX/CMakeCXXCompilerId.o: in function `main':
CMakeCXXCompilerId.cpp:(.text+0x0): multiple definition of `main'; CMakeFiles/3.26.4/CompilerIdC/CMakeCCompilerId.o:CMakeCCompilerId.c:(.text+0x0): first defined here

Or variants saying main was already defined

I also tried with this post and couldn't make it work either

0 Kudos
Reply
10 Replies

2,308 Views
ErichStyger
Specialist I
0 Kudos
Reply

2,305 Views
AgustinOrdonez
Contributor I
What about the other 2? Also I have multiple libc files, but none libc.a
0 Kudos
Reply

2,232 Views
ErichStyger
Specialist I

crt0.o is the startup code.

-lm means libm.a, the math library.

You have to check your linker files and tool setup, especially the linker command line.

0 Kudos
Reply

2,081 Views
AgustinOrdonez
Contributor I

Hey any recomendations on what to do? I couldn't find the reason of the 2 errors I have

0 Kudos
Reply

2,221 Views
AgustinOrdonez
Contributor I

I am testing both on linux and on windows, crt0.o, libm.a and libc.a exist on both systems.
On linux I am still getting the same error, it is probably some configuration I am missing and on windows I am getting the following:

cmd.exe /C "cd . && C:\PROGRA~1\ARM-GN~1.REL\bin\AR10B2~1.EXE -Wno-register -g -Wl,-gc-sections,--print-memory-usage,-Map=D:/Users/Usuario/Desktop/Agus/CodeStuff/TestLPC845/cmake-build-debug-arm/LPC845Test.map -mcpu=cortex-m0plus -mthumb -mthumb-interwork -T D:/Users/Usuario/Desktop/Agus/CodeStuff/TestLPC845/LinkerScripts/LPC845_Debug.ld CMakeFiles/LPC845Test.elf.dir/src/main.cpp.obj -o LPC845Test.elf   && cmd.exe /C "cd /D D:\Users\Usuario\Desktop\Agus\CodeStuff\TestLPC845\cmake-build-debug-arm && arm-none-eabi-objcopy -Oihex D:/Users/Usuario/Desktop/Agus/CodeStuff/TestLPC845/cmake-build-debug-arm/LPC845Test.elf D:/Users/Usuario/Desktop/Agus/CodeStuff/TestLPC845/cmake-build-debug-arm/LPC845Test.hex && arm-none-eabi-objcopy -Obinary D:/Users/Usuario/Desktop/Agus/CodeStuff/TestLPC845/cmake-build-debug-arm/LPC845Test.elf D:/Users/Usuario/Desktop/Agus/CodeStuff/TestLPC845/cmake-build-debug-arm/LPC845Test.bin""
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\libg.a(libc_a-closer.o): in function `_close_r':
closer.c:(.text._close_r+0xc): warning: _close is not implemented and will always fail
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\libg.a(libc_a-lseekr.o): in function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): warning: _lseek is not implemented and will always fail
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\libg.a(libc_a-readr.o): in function `_read_r':
readr.c:(.text._read_r+0x10): warning: _read is not implemented and will always fail
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\libg.a(libc_a-writer.o): in function `_write_r':
writer.c:(.text._write_r+0x10): warning: _write is not implemented and will always fail
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\crti.o: in function `_init':
(.init+0x0): multiple definition of `_init'; c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp/crti.o:(.init+0x0): first defined here
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\crti.o: in function `_fini':
(.fini+0x0): multiple definition of `_fini'; c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp/crti.o:(.fini+0x0): first defined here
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\crtbegin.o:(.data.__dso_handle+0x0): multiple definition of `__dso_handle'; c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp/crtbegin.o:(.data.__dso_handle+0x0): first defined here
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp\crtend.o:(.tm_clone_table+0x0): multiple definition of `__TMC_END__'; c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/thumb/v6-m/nofp/crtend.o:(.tm_clone_table+0x0): first defined here
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: Linker CRP Enabled, but no CRP_WORD provided within application
c:/progra~1/arm-gn~1.rel/bin/../lib/gcc/arm-none-eabi/12.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: cannot find entry symbol ResetISR; defaulting to 00000000
Memory region         Used Size  Region Size  %age Used
        MFlash64:        1236 B        64 KB      1.89%
        RamLoc16:         460 B        16 KB      2.81%
collect2.exe: error: ld returned 1 exit status


Here is a pastebin from CmakeLists.txt and also the linker file

 

 

0 Kudos
Reply

2,353 Views
ErichStyger
Specialist I

Obviously, you have multiple definitions of main() present. Check your source files, if you have more than one.

Additionally, you could turn on more verbose messages with

# Optional: print out extra messages to see what is going on. Comment it to have less verbose messages
set(CMAKE_VERBOSE_MAKEFILE ON)
0 Kudos
Reply

2,328 Views
AgustinOrdonez
Contributor I

Yes, those were some CMake's autogenerated ones, i didn't realize I was including /* instead of /*.*
I now have another issue which reports as follows:

 

 

/home/dioswilson1/Programs/clion-2022.1.2/bin/cmake/linux/x64/bin/cmake --build /home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm --target LPC845Test.elf -j 6
[1/1] Linking CXX executable LPC845Test.elf
FAILED: LPC845Test.elf
: && /usr/bin/arm-none-eabi-g++ -Wno-register -Wl,-gc-sections,--print-memory-usage,-Map=/home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm/LPC845Test.map -mcpu=cortex-m0plus -mthumb -mthumb-interwork -T /home/dioswilson1/CodeStuff/TestARMClion/LinkerScripts/LPC845_Debug.ld CMakeFiles/LPC845Test.elf.dir/src/main.cpp.obj -o LPC845Test.elf && cd /home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm && arm-none-eabi-objcopy -Oihex /home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm/LPC845Test.elf /home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm/LPC845Test.hex && arm-none-eabi-objcopy -Obinary /home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm/LPC845Test.elf /home/dioswilson1/CodeStuff/TestARMClion/cmake-build-debug-arm/LPC845Test.bin
/usr/lib/gcc/arm-none-eabi/13.2.0/../../../../arm-none-eabi/bin/ld: cannot find crt0.o: No such file or directory
/usr/lib/gcc/arm-none-eabi/13.2.0/../../../../arm-none-eabi/bin/ld: cannot find -lm: No such file or directory
/usr/lib/gcc/arm-none-eabi/13.2.0/../../../../arm-none-eabi/bin/ld: cannot find -lc: No such file or directory
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

 

I don't know what ld is looking for, I cannot find any "-lc", "-lm" or "crt0.o" neither on CmakeLists or in LinkerScript

0 Kudos
Reply

2,311 Views
AgustinOrdonez
Contributor I

Here is Linker script:

https://pastebin.com/QxWahvTD

Tags (1)
0 Kudos
Reply

2,319 Views
ErichStyger
Specialist I

'ld' is the GNU linker.

0 Kudos
Reply

2,316 Views
AgustinOrdonez
Contributor I
I know, i just realized i misspelled and said "-ld" instead of "-lc" my bad, I will edit previous post
0 Kudos
Reply