I'm amble to easily create a shared library in eclipse, setting project's proprerties:
C/C++ Build -> Settings -> Build Artifact
Artifact Type: Shared Library
Artifact Name: ${ProjName}
Artifact Extensione: so
Output Prefix: lib
So when I compile, output is:
lib<libraryName>.so
Question is: how can I automatically add version number? Like:
lib<libraryName>.so.1.0
I've no idea about.
I'm using SVN for version control.
Related
I am using Eclipse Eclipse 2022-09 with CDT 10.7.1202208222120 on Fedora 37.
I am working on a simple C++ testapplication (libTest.cpp) which should use code from 2 shared librarys (libBasexCpp and libBasexSocket).
All 3 sources compile without errors and building libTest also completes without error. In the Properties -> Settings -> Build Artifact dialog for libBasexCpp and libBasexSocket, I have chosen not to use a Output Prefix (prefix is ""). In the debug directorys, libBasexCpp.so and libBasexSocket.so are created.
When I try to run the testapplication as a local C/C++ application, I first have to choose which local application should be run , liblibTest or libTest.
Executing either one of the 2 results in a message, saying that liblibBasexCpp can not be found.
I have added Library Paths (DYLD_LIBRARY_PATH = ${workspace_loc:/libBasexCpp/Debug};${workspace_loc:/libBasexSocket/Debug} as Environmentvariable to the run configuration.
How can I configure Eclipse in such way that it loads the shared library's?
Basically, to configure the shared librarys and the test application, I followed the instructions as I found on Shared libraries with Eclipse CDT and cygwin on Windows.
What was missing therein was the instruction to add in the Run configuration the variable LD_LIBRARY_PATH containing the paths to both libraries.
After adding this variable, the test application worked.
I want to build two projects using cmake (A library and sandbox application using that library).
I'm currently having the following folder structure:
-- yanthra_engine
|
-- CMakeLists.txt
-- lib
-- ...
-- sandbox
|
-- CMakeLists.txt
-- out
-- ...
The yantra_engine builds a library where as sandbox builds an executable(using the above mentioned library).
Should I keep full fledged CMakeLists files for both the projects? Is there any efficient folder structure to follow?
I would like the library to build automatically when building my sandbox application, but not vice-versa.
You should keep seperate CMakeLists.txt files. It's good practice to use one CMakeLists.txt file per unrelated target. (Unrelated in the sense of not being different builds of the same library, e.g. one shared one static.)
Whether to add both targets to the same project is basically up to you. If the library is properly set up, you could create a seperate project for the library and use it's install target to install the library including cmake configuration files on your machine making it easy to import the installed library as a target to the sandbox project. This requires you to add the appropriate install commands to the library.
If you want to be able to build both the library and the sandbox via the same build files, basically all you need to do is to make sure both CMakeLists.txt files are reachable from a CMakeLists.txt file.
Without location of any of the files you could e.g.
Create a CMakeLists.txt file in the parent folder adding both subdirectories
cmake_minimum_required(VERSION 3.0)
project(CommonProject)
add_subdirectory(yanthra_engine)
add_subdirectory(sandbox EXCLUDE_FROM_ALL) # targets in sandbox not built by default.
You could also include the yanthra_engine directory from sandbox/CMakeLists.txt
...
add_subdirectory(../yanthra_engine "${CMAKE_BINARY_DIR}/yanthra_engine_build")
...
Both approaches allow you to either set up a build project for the lib on its own or set up a build project for both. In approach 1 the source directory for building both would be the parent directory of yanthra_engine and sandbox and in approach 2 it would be sandbox.
For both approaches you don't need to wory about unnecessarily building the sandbox project though as long as you specify the target you want to build. Since sandbox links the lib but there is no dependnecy established the other way round building sandbox makes sure the lib is up to date, but building the lib only builds the lib and its dependencies which excludes the sandbox.
One thing you can try is to let yanthra be a subdirectory of sandbox. Then you can do this in sandbox:
add_subdirectory(yanthra_engine)
I am using eclipse Version: Luna Release (4.4.0), MingW 32 bit compiler, window 64 bits along with libxml2-2.7.8.win32. I successfully compiled and build the project with no error but while i tried to run there is no output nor any error message.
I have specified path of 'lib' folder of libxml2 in eclipse as project-> Properties -> c/c++ build -> setting -> toolsetting -> mingW c++ linker -> libraries (-l) and Library search path (-L). In library i have used full name "libxml2" and search path i have placed "${workspace_loc:/${ProjName}/libxml2-2.7.8.win32/lib}"
there is a dll file "libxml2.dll" in the bin folder and have doubt whether i should place it some where or set reference path somewhere.
or should i use any c++ wrapper to execute the libxml2
I am trying to use POCO C++ Library with Netbeans IDE on Ubuntu Linux 13.04. I have downloaded, build and installed the POCO C++ Library. The library can be found in the directory "/usr/local/include/Poco". I would like to know how to add the POCO C++ Library to the Netbeans IDE and be able to work with it. Please answer with details.
Thank You
To link an external libraries you need in general three things:
To add the header files as an include directory -I flag
To add the library path to your POCO C++ *.so files -L flag
To add the library name to your compiler without the lib prefix, for example with poco would be poco-Foundation and the name of your file in your system would be libpoco-Foundation.so
Now for Netbeans specific
For the header files
File -> Project Properties -> Build -> C++ Compiler -> General -> Include Directories which is step one
For the library directories
Project -> properties -> Linker -> Additional Library Directories which is step two
For the library
Project -> properties -> Linker ->Libraries -> Add option -> Other is only for the library file, which is step three.
In the case of the Poco Libraries they are usually handled like the Boost Libraries, for example
#include "Poco/AutoPtr.h"
This means the Include Directory has to be one level up from the Poco folder. For example if your Poco folder is on "/usr/local/include/Poco" then you need to add the "/usr/local/include" to your Include Directories (from step one).
As for the -L/usr/local/include/Poco This is not how it is done. This path is the path to your specific library, in the case of poco there is Foundation, XML, Net, and Util along with the test projects. You need to find the files that are named libPoco-*.so where "*" means something. This is most likely in your the directory usr/local/lib if those files are not there then they are most likely in usr/local/lib/Poco
If there are no files named libPoco-*.so you have to build your Poco libraries separately.
How is it possible to make project in Eclipse CDT to target both static library and shared library?
(assuming you initially created a shared library project)
Create a new build configuration for static library (as you do for Debug/Release).
Right click on project
Build Configuration
Manage
New (follow instruction, e.g. name: Static)
Properties
C/C++ Build
Select the new configuration under "Configuration"
Build Artifact
Artifact type: Static Library
Build your configurations (e.g. Release, Debug, Static)
Right click on project
Build Configuration
Build
All
Release and Debug config should create your shared library
Static should create your static library