Closed ghost closed 3 years ago
@t0md3an
-l
), you can use:
foreign "GL" library
which will add -lGL
to your linker flags. You can also link to it via path:
foreign "shared_libraries/my_library.so"
I will think about adding -l
option straight to command-line too.
@t0md3an I haven't tested it, but there are probably problems with using Adept multiple times within the same project, so until I figure out a way to fix it, Adept should only be used once per project. However, C can be used as many times as desired within the same project.
A simple example of using Adept to make a library is here: https://github.com/IsaacShelton/Adept/tree/master/tests/export_import
Library A is written in C. Library B is written in Adept, and depends on Library A. The main program is written in C, and depends on Library B.
The example only makes .o
files, but .a
or .so
files can easily be made using ar
just like in C.
You just use gcc -c file.c -o file.o
and adept -c root.adept -o root.o
to build object files and then link them together like you would expect.
gcc -Wextra -Werror -c library_a.c -o library_a.o
adept --no-typeinfo -c library_b.adept -o library_b.o
gcc -Wextra -Werror -c main.c -o main.o
gcc main.o library_b.o library_a.o -o main
@IsaacShelton For linkable binary .a
there also must be header file:
#ifndef _HELLO_H_
#define _HELLO_H_ 1
#ifdef __cplusplus
extern "C" {
#endif
void hello();
#ifdef __cplusplus
}
#endif
#endif
After this C needs -l<lib>
and include this header file.
Where all the functions defined. Adept works just with linkable library without header file?
NOTE: I you will have some free time, can you create repository like https://github.com/t0md3an/c-lib (C library template) but for Adept? (I can’t understand)
@t0md3an
Adept doesn't read C header files, instead the "header file" is written like this:
/*--------------------------------------------*/
/* hello.adept - "Header file" for libhello.a */
/*--------------------------------------------*/
// This file requires that we link to 'libhello.a'
foreign "libhello.a"
// There exists a function called `hello` that is from C.
foreign hello() void
Adept only understands Adept code and C only understands C code, but both can link to .a
and .o
files.
Full examples of all the possible combinations of Adept/C libraries are here: https://github.com/IsaacShelton/AdeptWorkingWithC
Hopefully this helps explain it better
@IsaacShelton Add something like
-l
to Adept to allow linking Adept shared libraries. I created repository that tells about creating librarylib.a
in C, can you tell me how to do the same thing in Adept: