Closed parksj10 closed 1 year ago
Hi @parksj10, "ld returned 1 exit status" indicates a compilation error. It seems that the code has not been successfully compiled yet. Typically, our development process, including the release and GitHub versions, ensures that the code is thoroughly tested and compiles without any issues. However, considering the recent change in the CMakeLists.txt file, it might be necessary for you to investigate the root cause on your own first.
The issue likely occurs because your main file is a C++ source file, while the implementation of these functions is done in C source files. In this case, you have to inform the C++ compiler that the functions are declared with C linkage.
Please try adding #ifdef __cplusplus
/extern "C" {
/#endif
guards in your header file. Otherwise the C++ compiler will consider that the functions register_system
and others are declared with C++ linkage.
For more information about combining C and C++ code, please see the docs: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/cplusplus.html#combining-c-and-c-code.
@igrr you tha man! thanks! for reference for anyone else with this issue, this is the implementation of @igrr 's fix
// ./hw/components/blemesh_console/ble_mesh_console_decl.h
/* Console example — declarations of command registration functions.
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include "esp_ble_mesh_defs.h"
// Register system functions
void register_system(void);
// Register blutooth
void register_bluetooth(void);
// Register mesh node cmd
void ble_mesh_register_mesh_node(void);
// Register Test Perf client cmd
void ble_mesh_register_mesh_test_performance_client(void);
#if (CONFIG_BLE_MESH_CFG_CLI)
// Register mesh config client operation cmd
void ble_mesh_register_configuration_client_model(void);
#endif
// Register mesh config server and generic server operation cmd
void ble_mesh_register_server(void);
#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI)
// Register mesh client operation cmd
void ble_mesh_register_gen_onoff_client(void);
#endif
#if (CONFIG_BLE_MESH_CFG_CLI)
// Register mesh config client operation cmd
void ble_mesh_register_configuration_client_model(void);
#endif
#ifdef __cplusplus
}
#endif
@igrr out of curiosity, it's clear you have a ton of experience/expertise with this stuff, but how would someone such as myself know/figure out that this lack of C++ guard was causing the issue (I.e. from the ld
error I was getting)?
It's not a guaranteed way (there's always a chance of some odd bug haha!) but trying to follow the linker logic helps fairly often. Ask yourself questions like, "should the linker be able to find the library?", "is the function actually in the library?", "is the name of the function defined in the library same as the function being referenced?" and so on:
main
(a.k.a. hw/main/
)blemesh_console
.blemesh_console
is in the requires
list in hw/main/CMakeLists.txt
. Also, most of the time if the dependency at CMake level is missing, you will get a compile time error that the header file is not found.libblemesh_console.a
), and use objdump (xtensa-esp32-elf-objdump
) to check whether the functions are actually there.
#ifdef
which got preprocessed out_Z15register_systemv
instead of register_system
— this is the case you hadHope this helps!
That's super helpful! Thanks so much for all the details and help! I had no idea about the objdump
that's definitely gonna come in handy. I actually checked the build folder and saw the _Z15Register_...
thing but I didn't realize it wasn't supposed to be like that
I was having the same issue, using Arduino IDE 2.3.2 and trying to compile an example with the BluetoothSerial library from here: https://github.com/espressif/arduino-esp32/tree/master/libraries/BluetoothSerial , for the DFRobot Beetle ESP32-C3 and also SeeedStudio Xiao ESP32-C6.
I added `#ifdef __cplusplus extern "C" {
to the main code (seen below) and now am getting the `exit status 1
Compilation error: conflicting declaration of 'void setup()' with 'C' linkage` error. Any help? Complete code I am trying to compile on Arduino IDE:
`#include "BluetoothSerial.h"
extern "C" {
BluetoothSerial SerialBT; String MAC_Address;
void setup() { Serial.begin(115200); SerialBT.begin("ESP32 Bluetooth"); }
void loop() { MAC_Address = SerialBT.getBtAddressString(); Serial.println(MAC_Address.c_str()); delay(500); }`
Answers checklist.
IDF version.
v4.4.4
Operating System used.
macOS
How did you build your project?
Command line with idf.py
If you are using Windows, please specify command line type.
None
What is the expected behavior?
I expect the project to build
What is the actual behavior?
I get ld link errors
Steps to reproduce.
Build or installation Logs.