This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Best way to share code between proyects

Tags: None
(comma "," separated)
Xorlium
Registered Member
Posts
17
Karma
0
OS
Hello,

I'm not an expert developer, and I use C++ for mathematics (combinatorics) research to test out possibilities. I've created a (shared) library containing many useful functions that I use in many of my little projects, but right now I'm copy-pasting the whole directory into all my projects. Of course, I often edit something or add something to the library, so this is obviously not a good way.

What I want is for each project to be in its own directory, but "linked" somehow to the shared-library-project, so that when I compile any of my projects, the shared-library-project compiles too, copies the libwhatever.a into somewhere everything can access it, and links it. In Cmake I tried doing this just by saying "add_subdirectory(../mylib)" but it doesn't work, it says the root directory has to be, well, at the root. But I don't want to have the library inside any specific project directory, because then all the others won't work.

Any ideas?

Thank you.
Tupla
Registered Member
Posts
47
Karma
0
OS
Why don't you create a static library and install it in your library path (for instance /usr/lib)? Then it is sufficient to link your projects against that library (being in the default path should be found without problems).
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Hello,

you can also just use target_link_libraries() in cmake with a path to a shared library file. That'll link against that file.
That would even work without installing the library system-wide.

Greetings,
Sven


I'm working on the KDevelop IDE.
Xorlium
Registered Member
Posts
17
Karma
0
OS
Well, the system wide doesn't work because I would need to constantly install (since it's being changed all the time). The other one... well, I guess that would work on my system, but what about if I re-distribute stuff? They'll need the same paths. Unless I can do this with a relative path... I'll try.

Thanks,
Xorlium
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Well, in that case you would of course install it into a system-wide path. If you want to get more advanced, you can also ship with a Find<Foo>.cmake file which will figure out the path.

Greetings


I'm working on the KDevelop IDE.


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan, Sogou [Bot]