Author Topic: How develop libraries & classes in any directory and include it in main file?  (Read 1235 times)

Offline R1S8K

  • Multiple posting newcomer
  • *
  • Posts: 10
Hello,

I'm just starting my C++ debugging and programming, my main goal is to learn how to write classes and develop C++ libraries.

I know that codeblocks requires me to include the classes and libraries inside the project folder, but I want to link classes and libraries outside the project folder. How to do that?

===================================================
Edit1: I tried to include it with "Add files..." from the project tree, but didn't work.

... OK I wanted to include an image but didn't know how to ! Could anyone tell me how to include an image?
« Last Edit: May 21, 2019, 08:13:29 pm by R1S8K »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2547
Quote
===================================================
Edit1: I tried to include it with "Add files..." from the project tree, but didn't work.
What "didn't work" mean? Error messages? Compiling problems?
please give more details about your error:
Also take this as help: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

Quote
... OK I wanted to include an image but didn't know how to ! Could anyone tell me how to include an image?
This is a extreme broad question:
1) Do you want to add an image to wxSmit?
2) Do you want to add an to a console application?
3) What file format has the image?
4) Are you using a library to load the image?

Offline R1S8K

  • Multiple posting newcomer
  • *
  • Posts: 10
OK, now the attach image icons are available now :)

Quote
This is a extreme broad question:
1) Do you want to add an image to wxSmit?
2) Do you want to add an to a console application?
3) What file format has the image?
4) Are you using a library to load the image?

Yes, I just wanted to include an image here in my last post. Here it's:

Quote
What "didn't work" mean? Error messages? Compiling problems?


Offline stahta01

  • Lives here!
  • ****
  • Posts: 6666
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6666
    • My Best Post
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline R1S8K

  • Multiple posting newcomer
  • *
  • Posts: 10
I tried that solution but I think I don't know what I'm doing.

I tried to add the main path for the project, but didn't work.

I did 2 things according to the link provided.

1. Add the main class libraries in the settings menu/compiler/Search directories/Compiler and Linker tabs I added the main path
2. Project/Build options/Search directories/Compiler and Linker tabs I added the main path

F:\computer_programming_dev\Programming_exercises\C++\classes\

This path contains:

1. 2 classes example folders
2. 1 main program folder

An this path contains the attached picture.


But the same problem, what I'm missing !



===================================================================================

BUT ! I actually developed those classes as simple new classes from File/New/Class

I thought that's it! That what it takes to develop a class library that can be used as #include "lib_ex.h" in projects. But when I search for them I actually don't find its library specific files like .a ... etc. They are just .cpp and .h files ! Does that consider these two files as library ?

I think I have to choose a complete new project library from the start as: static, dynamic or shared library. I think just developing a class that is .cpp or .h is what it takes for what I want!


So I want to develop a class library that can be included in a project, what should I choose of the three, static, dynamic or shared library?
« Last Edit: June 10, 2019, 02:48:01 am by R1S8K »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2547

Offline R1S8K

  • Multiple posting newcomer
  • *
  • Posts: 10
OK, I was able to solve the previous problem by developing a shared library in the main projects folder.

The main projects folder contains:
1. Application project folder.
2. Shared library example folder.

So I could include the new shared library, but when I tried to run the function from the shared library into the main project source file, I got an error saying
Quote
the code execution cannot proceed because .dll was not found

So I had to copy the shared library .dll file into the bin folder of the main project folder. And problem is solved.

My new question is:
How to include the .dll files in the main project bin folder automatically?

Now, if I've done anything new in the library, then I have to compile it and then copy the .dll file again into the bin of the main application folder.
« Last Edit: June 13, 2019, 07:38:54 am by R1S8K »

Offline R1S8K

  • Multiple posting newcomer
  • *
  • Posts: 10
Update2:
OK, I solved the problem of linking .dll files.


My question now is relatively general to how things work with code blocks. Now, what should I add to the main project in the build option every time I want to include a new library? Do I have to do the same procedure of adding the .a and .dll paths ?