Multiple C files compiled together using the CMakeLists

Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

Multiple C files compiled together using the CMakeLists

Postby Palonso » Sat Jan 25, 2020 1:08 am

Hi,

I have a file tree like this:

Code: Select all

- myProject/
             - CMakeLists.txt
             - sdkconfig
             - components/ - component1/ - CMakeLists.txt
                                         - Kconfig
                                         - src1.c
                           - component2/ - CMakeLists.txt
                                         - Kconfig
                                         - src1.c
                                         - include/ - component2.h
             - main/       - CMakeLists.txt
                           - src1.c
                           - src2.c

             - build/
and I have been trying to compile it, but it constantly says that some functions have multiple definitions (or sometimes it does that with global variables).

On my research I found that some of those elements have to be extern and tried adding extern but keep having the same problem of multiple definitions or errors with parameter inside the function/variable.

I also find that you can compile various *.c files by changing (or adding) something on the CMakeLists files, Can someone give a simple example of how to do that?

PS: I tried

Code: Select all

idf_component_register(SRCS "src1.c" "src2.c"
                       INCLUDE_DIRS "."
                       COMPONENT_EMBED_FILES "aWebPage.html")
In mi myProject/main/CMakeLists.txt, But is not working somehow.

Regards,
P


Palonso
Posts: 95
Joined: Tue Sep 24, 2019 8:43 pm

Re: Multiple C files compiled together using the CMakeLists

Postby Palonso » Mon Jan 27, 2020 4:41 pm

Exactly that's my problem.

I tried what the "Build system" sections says and couldn't manage to build the code. I also looked after the FTP server example, since it has two *.c files, and even "copying" that example I wasn't able to build the code.

That's why i was asking for a more detailed example of how to do that.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Multiple C files compiled together using the CMakeLists

Postby ESP_Angus » Tue Jan 28, 2020 5:15 am

Hi Palonso,

Does the src1.c file have the same contents in all 3 places? This can't work in C, you can only define a global name in one place and then anywhere else you can use an "extern TYPE NAME;" type declaration to link to the definition in the other source file. You can google for "declaration definition C" to find out more about the difference between these two things.

If this isn't the problem, can you please give some more details (for example: exactly what error messages you get when building, where the things which are named in the errro are located, what the contents of the CMakeLists files are, etc)?

Who is online

Users browsing this forum: No registered users and 152 guests