Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Adding C static library to my project(How to add an external static library to my C project and use its functions)
Adding C static library to my project [message #1769764] Thu, 03 August 2017 05:04 Go to next message
Eclipse UserFriend
I've been working on a project for embedded system and it needs SSL/TLS functionality.

I downloaded SSL project from GitHub (WolfSSL to be specific), compiled it with autotools, then created a static library libwolfssl.a using ar from libtools which archived all the .o files

I need to use the functions implemented in WolfSSL in my code, for example SSL_Library_Init()

How can I add the static library and use the functions using Eclipse IDE ?

I tried the following:

Added library path to the C linker -L: ${workspace_loc:/${ProjName}/lib}
Added library name to -l : wolfssl where the library name is libwolfssl.a
When I try to build the project, anything related to SSL is not recognized yet, ex: SSL_Library_Init and so on
Is this the correct way to do this?
Re: Adding C static library to my project [message #1769822 is a reply to message #1769764] Thu, 03 August 2017 13:01 Go to previous messageGo to next message
Eclipse UserFriend
You have done this correctly, based on the information you provided.

Please include the command line and error message from the Console so that we can have a better understanding of what "not recognized" means in this context.
Re: Adding C static library to my project [message #1769825 is a reply to message #1769764] Thu, 03 August 2017 14:01 Go to previous messageGo to next message
Eclipse UserFriend
If you did not specify it separately, Autotools will compile object files for the computer the translation is done on. It may need special handling to cross-compile the library for your embedded system.
Re: Adding C static library to my project [message #1769844 is a reply to message #1769764] Fri, 04 August 2017 02:32 Go to previous messageGo to next message
Eclipse UserFriend
index.php/fa/30272/0/
I collected all the object files that "make" command generate as per the above image attached
index.php/fa/30269/0/
I executed the comman "ar" to create a static library out of those files and I called it libwolfsll.a
index.php/fa/30271/0/
The above images shows how I added this library to Eclipse
index.php/fa/30270/0/
The SSL functions I need to call are in the file shown in this image, I tried to #include it in the fine tls_funcs.c that needs to call them but I am getting many errors that they are not declared as if the library is not there at all.

Am I doing it correctly?
  • Attachment: arcmd.PNG
    (Size: 1.09KB, Downloaded 3891 times)
  • Attachment: sslfuncs.png
    (Size: 91.99KB, Downloaded 4036 times)
  • Attachment: libs.PNG
    (Size: 3.47KB, Downloaded 3895 times)
  • Attachment: ofiles.PNG
    (Size: 41.87KB, Downloaded 3941 times)
Re: Adding C static library to my project [message #1769845 is a reply to message #1769764] Fri, 04 August 2017 02:33 Go to previous messageGo to next message
Eclipse UserFriend
Duplicate**

[Updated on: Fri, 04 August 2017 02:36] by Moderator

Re: Adding C static library to my project [message #1769876 is a reply to message #1769845] Fri, 04 August 2017 08:01 Go to previous messageGo to next message
Eclipse UserFriend
The first error is saying there is no definition for SSL3_RANDOM_SIZE.
The second and third are saying that what ssl is pointing toward is declared only as a forward declaration such as "struct ssl_;" .
I would think that the build had stopped before reaching the link stage so your questions about linking the library appear premature.
You should fix the depicted problems first.

Your post suggests a misunderstanding of what is going on.
The -L,-l are options telling the linker where to find the compiled functions which have been collected into an archive.
The compiler is interested only in the interface to those functions.
These are usually specified in an included header (.h) file.

[Updated on: Fri, 04 August 2017 08:20] by Moderator

Re: Adding C static library to my project [message #1769877 is a reply to message #1769876] Fri, 04 August 2017 08:15 Go to previous messageGo to next message
Eclipse UserFriend
Yes the build has stopped before linking.
These definitions are implemented in the library I am trying to link to.
ex: SSL_RANDOM_SIZE and so on
They are within the build library
I need to call them explicitly and be able to recognize them.
Re: Adding C static library to my project [message #1769879 is a reply to message #1769877] Fri, 04 August 2017 08:23 Go to previous messageGo to next message
Eclipse UserFriend
I edited my post to say:

Quote:
Your post suggests a misunderstanding of what is going on.
The -L,-l are options telling the linker where to find the compiled functions which have been collected into an archive.
The compiler is interested only in the interface to those functions.
These are usually specified in an included header (.h) file.


The header file you used appears incomplete.

Re: Adding C static library to my project [message #1827992 is a reply to message #1769879] Thu, 28 May 2020 11:11 Go to previous messageGo to next message
Eclipse UserFriend
Hello friends,
I am new in Eclipse so plz guide me for adding WolfSSH library to eclipse project.
any one have an idea about this process plz share me.Here i want to reduce memory of SRAM.
Now i am using STM32F4 micro controller.
Re: Adding C static library to my project [message #1828000 is a reply to message #1827992] Thu, 28 May 2020 17:30 Go to previous message
Eclipse UserFriend
Your question is really broad.
It's the logical equivalent of purchasing a machine shop with lots of tools
then asking how to build an automobile with it.
If you don't already know how, you likely wouldn't understand the answers.

The short answer is: it's complicated.
A somewhat longer answer is:

  • You write your code
  • Tell the compiler where to find the library interface descriptions (header files)
  • Tell the linker how to generate an executable (libraries to use and where to find them)
  • Convert the executable into one you can use on your target machine
You really need to know how to do that without using Eclipse.
Afterwards, it will become rather obvious how to set the options when using Eclipse.

Eclipse uses Make (or some functional equivalent) to perform builds.
A Makefile usually breaks the build task into (1) compiling modules then (2) linking them.
If Eclipse is not generating the Makefile then you don't tell it anything -- your Makefile does it all.

My suggestion is learn how to compile and link executables from the many tutorials available on the Internet.

Once you understand how to do that and you still don't understand how to tell Eclipse
then post a new question with specifics on what you've tried and what you expected.

[Updated on: Fri, 29 May 2020 03:57] by Moderator

Previous Topic:Editor havyly blinking on ubuntu
Next Topic:Add custom tool to toolchain
Goto Forum:
  


Current Time: Wed Jul 23 08:36:07 EDT 2025

Powered by FUDForum. Page generated in 0.06549 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top