(solved) problem converting C program to C++

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(solved) problem converting C program to C++

Postby mzimmers » Thu Dec 27, 2018 7:52 pm

Hi all -

I was hoping not to have to drag this subject up again, but...I've reviewed my old posts on this topic and can't find what I'm doing wrong.

I began with a copy of a C project (https://github.com/OLIMEX/ESP32-POE/tre ... E_Ethernet) and renamed the two C files to .cpp. I added the extern "C" linkage as follows:

Code: Select all

extern "C" void app_main(void)
{
...
and did the same for olimex_ethernet.cpp and olimex_ethernet.h. Ran a make using msys2, and got this error:
$ make
CXX build/main/main.o
AR build/main/libmain.a
LD build/ESP32-PoE.elf
C:/esp32_projects/esp32_poe_ethernet/build/main\libmain.a(main.o):(.literal.app_main+0x28): undefined reference to `testEthernet'
C:/esp32_projects/esp32_poe_ethernet/build/main\libmain.a(main.o): In function `app_main':
C:/esp32_projects/esp32_poe_ethernet/main/main.cpp:64: undefined reference to `testEthernet'
Can someone remind me what I'm forgetting? Thanks.
Last edited by mzimmers on Wed Jan 02, 2019 2:52 pm, edited 1 time in total.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: problem converting C program to C++

Postby fly135 » Thu Dec 27, 2018 10:45 pm

Do a make clean. I don't see where it's building the other dot cpp file.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem converting C program to C++

Postby mzimmers » Thu Dec 27, 2018 10:56 pm

Already tried a make clean...no change. You're right, though -- make doesn't seem to have any knowledge of olimex_ethernet.cpp. I touched it and did another make, and it didn't try to compile it. Isn't the make facility suppose to automatically pick up all source files? This one is in a subdirectory under ~project/main.

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: problem converting C program to C++

Postby mikemoy » Fri Dec 28, 2018 5:55 am

Not sure if this is the issue, but there is an option for c++ in menuconfig.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem converting C program to C++

Postby mzimmers » Fri Dec 28, 2018 4:07 pm

The only C++ options I found in menuconfig were:

CONFIG_CXX_EXCEPTIONS=y
CONFIG_CXX_EXCEPTIONS_EMG_POOL_SIZE=0

Was there another one you saw?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem converting C program to C++

Postby mzimmers » Fri Dec 28, 2018 5:59 pm

As an update, the problem doesn't appear to be C vs. C++ after all. The project uses the following source files:

main/main.cpp
main/ethernet/olimex_ethernet.cpp
main/ethernet/olimex_ethernet.h

And main doesn't seem to be looking in main/ethernet/.

Do I need to do something to get make to look in a subdirectory?

ESP_Sprite
Posts: 9727
Joined: Thu Nov 26, 2015 4:08 am

Re: problem converting C program to C++

Postby ESP_Sprite » Sat Dec 29, 2018 8:12 am

Does the ethernet .h file also have the extern c linkage things?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem converting C program to C++

Postby mzimmers » Sat Dec 29, 2018 3:14 pm

Yes it does.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: problem converting C program to C++

Postby fly135 » Sun Dec 30, 2018 4:06 pm

When I have problems like this, I usually end up solving by adding something to component.mk telling it where to look for files.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem converting C program to C++

Postby mzimmers » Sun Dec 30, 2018 4:52 pm

Hey Fly - that was good advice. I'd been assuming all along that the build system knew to look in subdirectories, but that turned out not to be the case. in main/component.mk, I added this line:

Code: Select all

COMPONENT_SRCDIRS := . ethernet
And it builds now. The "." is needed if you have source files in your main/ directory.

It's good to have this working, even if Cmake is the wave of the (esp32's) future. Thanks for the suggestion.

Who is online

Users browsing this forum: Bing [Bot] and 87 guests