undefined reference

Troubleshooting an error: "/path/to/file.c:6: undefined reference to "methodName" collect2: error: ld returned 1 exit status".

Note: Deplink is still under development. Documentation can be incomplete or contains outdated information

Context

Problem occurs while building project written in C which uses libraries written in C++.

Problem

Example output of build command which contains exception:

wojtek@vm:~/Downloads/hello-world$ deplink build --verbose
Retrieving installed dependencies... OK
Resolving dependencies tree... OK
Dependencies: 0 installs, 0 updates, 0 removals
Writing lock file... OK
Generating autoload header... OK
Dependencies: 0 builds, 1 up-to-date
Building project...
build/x86/hello-world.o: In function `main':
/home/wojtek/Downloads/hello-world/src/main.c:6: undefined reference to `sayHello'
collect2: error: ld returned 1 exit status
build/x64/hello-world.o: In function `main':
/home/wojtek/Downloads/hello-world/src/main.c:6: undefined reference to `sayHello'
collect2: error: ld returned 1 exit status

Solution

We recommend to provide C linkage for C++ functions using the syntax:

extern "C" void sayHello(const char* name);

See below issues for more information: