Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use as shared library #2

Closed
Calmly145 opened this issue Apr 30, 2020 · 14 comments
Closed

Use as shared library #2

Calmly145 opened this issue Apr 30, 2020 · 14 comments

Comments

@Calmly145
Copy link

It there a possibility to make the library as an shared library for a unix arm based system?
I'm trying to use it on raspbian, but i cannot get the linking of the libraries right.

@GlitchedPolygons
Copy link
Owner

Hm, its only dependency is MbedTLS, which is being maintained by ARM themselves.
It should therefore build just fine, as long as you have CMake and a compatible compiler installed. You can force building shared libs by passing -DBUILD_SHARED_LIBS=ON to the cmake command.
If you want to build the MbedTLS dependency as a shared library as well, you need to pass -DUSE_SHARED_MBEDTLS_LIBRARY=ON (it has its own parameter for that).

But yeah, I know that linking libraries in C ain't always fun...
I don't have a Pi to test this on atm, but if you manage to get it to work please post it here so I can close the issue and others can learn too :)

Cheers

@Calmly145
Copy link
Author

Calmly145 commented Apr 30, 2020

I did manager to make the library a shared library. At least the MbedTLs dependencies. The l8w8jwt is still static. This was all done with Cmake
But the including the library in my project is a pain. As not all the links are working well with the files as i'm using gcc for my project.
But i will give an update when i can
ps. you do not make use of jansson, correct ?

@GlitchedPolygons
Copy link
Owner

I did manager to make the library a shared library. At least the MbedTLs dependencies. The l8w8jwt is still static. This was all done with Cmake
But the including the library in my project is a pain. As not all the links are working well with the files as i'm using gcc for my project.
But i will give an update when i can

Thanks for the info! I'll look into it as soon as I have the time. Sounds strange, it should build shared libs with that option..

ps. you do not make use of jansson, correct ?

Correct. The only significant (in terms of heaviness) dependency is MbedTLS. The other 3 you can check out inside the lib/ folder. Jansson is not one of them.

@GlitchedPolygons GlitchedPolygons pinned this issue Apr 30, 2020
@Calmly145
Copy link
Author

I got the first part working to build the shared libraries and install them with the following method:

  • git clone https://github.com/GlitchedPolygons/l8w8jwt.git
  • cd ./l8w8jwt/
  • mkdir build
  • cd build
  • cmake .. -DBUILD_SHARED_LIBS=ON -DUSE_SHARED_MBEDTLS_LIBRARY=ON
  • make all && sudo make install
  • sudo cp /home/username/l8w8jwt/build/libl8w8jwt.so /usr/lib
  • sudo chmod 777 /usr/lib/libl8w8jwt.so
  • ldconfig

And then add -ll8w8jwt to you gcc build command.

But i'm currently a bit stuck on, how to #include l8w8jwt/decode.h

@GlitchedPolygons
Copy link
Owner

Did you include the l8w8jwt include directory via GCC's -I argument too?

@Calmly145
Copy link
Author

to add the library i did

gcc -o -Wall Project -g "all the other libraries" -ll8w8jwt

The include is for in my source code header file
#include <l8w8jwt/decode.h>
Which i think i'm doing something wrong. Or maybe a wrong link

@GlitchedPolygons
Copy link
Owner

GlitchedPolygons commented Apr 30, 2020

try adding -Ipath/to/l8w8jwt/include

https://www.rapidtables.com/code/linux/gcc/gcc-i.html

@Calmly145
Copy link
Author

Calmly145 commented Apr 30, 2020

if i add that piece to the gcc builder. It is missing the other parts
In file included from ../../../l8w8jwt/include/l8w8jwt/decode.h:34:0,
from ../main/project.c:3:
../../../l8w8jwt/include/l8w8jwt/claim.h:31:23: fatal error: chillbuff.h: No such file or directory
#include "chillbuff.h"

Currently trying to move and fix the header files linking

@GlitchedPolygons
Copy link
Owner

ah, true! Those are needed as well. Add -Ipath/to/l8w8jwt/lib/chillbuff/include, and the same thing for checknum and jsmn respectively.
Or you could also switch to using CMake for you project too, so you can just add_subdirectory(path/to/l8w8jwt) and then link using CMake

@Calmly145
Copy link
Author

Calmly145 commented Apr 30, 2020

I made it easier, by coping the header files to the same file . So you don't get to many -I links in the build command

l8w8jwt/include

When i build that piece i get no error and i get the proper output from the example piece of code

@GlitchedPolygons
Copy link
Owner

I understand :)

I'll close this issue then, and wish you good luck with your project!

@Calmly145
Copy link
Author

Maybe an idea, to add these steps to your guide. So other people can also use it for there projects in this way

@GlitchedPolygons
Copy link
Owner

The intended usage is definitively with a build system (CMake in this case). It's so much more pleasant!

But if you're okay with it, I could add a small GCC section inside the README.md that links to our conversation in this issue?

@Calmly145
Copy link
Author

I understand that is the use case for the project. But it's a little extra for the people who do it with gcc. And gives an extra option for your library to be used :)

I'm oke with linking to this conversation

GlitchedPolygons added a commit that referenced this issue Apr 30, 2020
Added GCC instructions to README.md (by linking to issue #2 ). Special thanks to @Calmly145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants