Author Topic: How to use an already compiled library?  (Read 1387 times)

Offline cbun

  • Single posting newcomer
  • *
  • Posts: 2
How to use an already compiled library?
« on: March 17, 2021, 09:04:34 am »
Hi, I'm new to Code:Blocks.
In my current C++ project I'm using a library (lib***.a) located with the header and source files in a certain folder.
I can compile and run my project but it does take ages to do so (over 2 min).
Instead of compiling just my file and using the library it does compile all of those files an shows a lot of warnings in those. It does this after each little change.
What did I miss?

Currently I'm using a newer version of the library. Before that I used an older version available in package sources of Ubuntu. But that needed an extra path as well.
Also had this Problem there. But somehow I managed it to work there (did also including restarting Code::Blocks).
Now I only get some short building time after building it once and dont change anything in code.



I did add the absolute folder path to:
- Project->Properties->C/C++ parser options
- Project->Properties->Debugger
- Project-> Build Options -> (select project name to the left) -> Search directories -> compiler
- Project-> Build Options -> (select project name to the left) -> Search directories -> linker
And did the path to the library itself:
- Project-> Build Options -> Compiler Settings -> Other resource compiler settings -> -l/pathto/libname.a
- Project-> Build Options -> Linker Settings


In console I can compile it with (in less than 5 sec):
g++ -o test ./main.cpp -L/pathtolibraryfolder/ -libname -I/pathtoheaderfolder_equalToLibfolder/
« Last Edit: March 17, 2021, 09:38:13 am by cbun »


Offline cbun

  • Single posting newcomer
  • *
  • Posts: 2
Re: How to use an already compiled library?
« Reply #2 on: March 18, 2021, 12:05:23 am »
Thank you for response BlueHazzard.
Today somehow it took 'only' 40 sec.

I checked the build log. It included a lot of warning from my included headers (from that library).
After changing '-Weverything' to '-Wall' in build options it did only show warnings for my file.
After changing this building took only 2 sec.

with this build log is:
Code
Cleaned "myproject - Debug"

-------------- Build: Debug in myproject (compiler: LLVM Clang Compiler)---------------

clang++ -Wall -g -fexceptions -I/home/username/Downloads/libs/libraryname -c /home/username/Projects/CodeBlocks/myproject/main.cpp -o obj/Debug/main.o
clang++ -L/home/username/Downloads/libs/libraryname -o bin/Debug/myproject obj/Debug/main.o  -lraryname  /home/username/Downloads/libs/libraryname/libraryname.a
Output file is bin/Debug/myproject with size 22.18 MB
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))

« Last Edit: March 18, 2021, 12:12:39 am by cbun »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3003
Re: How to use an already compiled library?
« Reply #3 on: March 18, 2021, 07:15:19 pm »
Yes, codeblocks has some problems with warnings, at least on windows...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: How to use an already compiled library?
« Reply #4 on: March 18, 2021, 09:22:32 pm »
It is not a windows only problem. :(
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]