cancel
Showing results for 
Search instead for 
Did you mean: 

VSCode STM32 error: ld returned 1 exit status

DeemDeem52
Associate II

Hello, 

I'm working on a project for a Nucleo board for which I'm trying to use VSCode. I've installed the relevant extensions, and building and running the project had been working, but suddenly (after changing the .ioc file in CubeMX) it stopped working (even when I undid my change); now, every time I build or clean build, I get the error:

collect2.exe: error: ld returned 1 exit status
MAKE.EXE: *** [STM32Make.make:211: build/CTS-SAT-1_FW.elf] Error 1

The file in question here seems to say this:

$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) STM32Make.make
    $(CC) $(OBJECTS) $(LDFLAGS) -o $@
    $(SZ) $@

Alas, this is entirely incomprehensible to me.

Can anyone help me figure this out?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Hey there! Thanks for the information.

I found the solution -- when I updated the code using CubeMX in the .ioc file, it removed a number of lines from the makefile which were under C_SOURCES, which without those, VSCode didnt't know where to find the .c files. Adding them back fixed everything!

Thanks again.

View solution in original post

6 REPLIES 6
Pavel A.
Evangelist III

This means that the linker (ld) failed and returned exit status 1. The makefile itself is not broken.

There should be more detailed log (or previous messages not shown) that explains the linker error.

 

 

DeemDeem52
Associate II

Thanks for your reply. I still don't really understand what the error is, but I have attached the full log as a .txt file. I'm assuming it's some sort of flag issue, but I don't know.

Pavel A.
Evangelist III

A lot of well known library functions can't be found. The project likely does not reference the library files correctly.

If you received this project from other person, ask them to fix. Else, a ready example can help.

 

Nawres GHARBI
ST Employee

@hi @DeemDeem52 

Could you share your project or ioc


@DeemDeem52 wrote:

 I still don't really understand what the error is, .


An "undefined reference", eg to HAL_UART_Transmit(),  means that you have called the function, but have not provided any definition (ie, the implementation; the executable code) for that function.

Usually, this means that you have just #included a header file which contains the prototype for the function - but you haven't included the source file or pre-built binary library which provides the implementation of that function.

For and example of why you need both the header and the source file, see:

https://community.st.com/t5/stm32cubeide-mcus/adding-new-c-source-files-to-my-project-and-navigating-through/m-p/657455/highlight/true#M25847

In the case of the HAL... functions, they are supplied as source code.

 

Hey there! Thanks for the information.

I found the solution -- when I updated the code using CubeMX in the .ioc file, it removed a number of lines from the makefile which were under C_SOURCES, which without those, VSCode didnt't know where to find the .c files. Adding them back fixed everything!

Thanks again.