SanderMertens / bake

Bake, A build system for building, testing and running C & C++ projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failing to link package

Ruannilton opened this issue · comments

I have a package that I am porting to the bake environment:
{ "id": "collections", "type": "package" }

and an application project thats depends on it:
{ "id": "collec_test", "type": "application", "value": { "use": [ "collections" ] } }

But when try to compile I get this error:

ruan@Mahlik:~/Dev/collec_test$ bake build
[ build] application collec_test => '.'
/usr/bin/ld: .bake_cache/x64-Linux-debug/obj/main.o: in function 'main':
/home/ruan/Dev/collec_test/./src/main.c:5: undefined reference to 'cvector_create_i'
collect2: error: ld returned 1 exit status
[ error] process 4040 exited with returncode 1
[ from] command returned 1
gcc -Wall -O0 .bake_cache/x64-Linux-debug/obj/main.o -L/home/ruan/bake/x64-Linux/debug/lib -L/home/ruan/bake/lib -lcollections -o ./bin/x64-Linux-debug/collec_test
[ from] command for task './bin/x64-Linux-debug/collec_test' failed
[ from] failed to build rule 'ARTEFACT'
[ error] build interrupted for collec_test in .
[ error] project 'collec_test' built with errors, skipping

When I go to the lib directory the .so file is presente there:

ruan@Mahlik:~/bake/x64-Linux/debug/lib$ ls
libcollections.so

And when I list the bake enviroment the package is there:

ruan@Mahlik:~$ bake list

Listing projects for platform:

  • x64-Linux

Packages & Applications:
P bake.amalgamate => all
C bake.lang.c => all
C bake.lang.cpp => all
C bake.opengl => all
C bake.sdl2 => all
C bake.sfml2 => all
P bake.test => all
P bake.util => all
P collections => [debug]

Summary:
applications: 0, packages: 9, templates: 0

The package code works well in other projects, so, I believe the cvector_create_i function is defined in the .so file.
Could someone explain to me what's wrong please?

Disclaimer: I'm new to c, and I don't understand why/how this works.

To make cvector_create_i available in your collec_test application, you'll need to edit your main header file in the collections project (i.e. collections/include/collections.h). Try adding COLLECTIONS_API in front of the cvector_create_i definition.

COLLECTIONS_API void cvector_create_i();

Then, rebuild your app project with bake rebuild -r.

For me at least, running the app binary directly gives me an additional error message, but when I used bake run, I was able to run the app and call the package function.