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
Related
When I Install packages using vcpkg, it creates lib and Debug/lib, in which are the static libraries. but I wonder what is the difference between them, since I can use both of them as the library path in my Visual Studio C++ Project and both ways can build the project successfully...
(I know that in the debug directory, the libs are for debug. But I only add, for example, imgui.lib, to the "Additional Dependencies", and I set debug/lib(which only has imguid.lib) as the library path, the projected also can be built successfully...How does VS know that imguid.lib is the imgui.lib?)
Root Directory
lib
debug/lib
Our project structured like this.
1) MainApp, it loads dlls dynamically by using boost, and all the dlls projects/modules are build with /MD.
2) Any other projects that is needed by these dlls are built as static (.lib) or dynamic (.dll) lib. There is no problem when these dependency libraries are dynamic since I can use the same MD. However, if those are static, I have to build them with MD instead of default MT, otherwise it can't be loaded in these dlls.
This has worked all the times until I am trying to compile google cloud sdk c++.
Here is the problem: Google cloud c++ sdk has many dependencies that come with the google git, BUT Google only include (or build default) the static(/MT) version. And they don't even provide options to change to MD. I can change the google cloud lib from /MT to /MD by using cmake command set(CMAKE_CXX_FLAGS_RELEASE "/MD"), but this won't build because its dependency are /MT.
Simplified situation:
MainApp.exe dynamic loads -> Function.dll (/MD), then Function.dll static links Google_cloud.lib (.lib but with /MD), then Google_cloud.lib static link its dependencies (.lib with /MT, can't change it to /MD)
So I guess the only option is to manually custom build google cloud's static dependency with /MD and then build google cloud as static with /MD then loaded by my function.dll as static.
Any suggestion?
You can mutate the BUILD_SHARED_LIBS flags which will cause the default library type to be shared libraries.
Another way is simply to pass the right argument to the add_library command:
add_library(lib1 SHARED a.cpp b.cpp)
add_library(lib2 STATIC a.cpp b.cpp)
add_library(lib3 a.cpp b.cpp) # use the BUILD_SHARED_LIBS value
I have an eclipse c++ project with two shared libraries. I've included the names of the libraries and their paths under the project settings. The project builds fine, but I cannot run it:
error while loading shared libraries: libxxx.so.0.3.1: cannot open shared object file: No such file or directory
Do I have to set the ld_library_path variable to run the project in eclipse?
Do I have to set the ld_library_path variable if i want to run the application in the console?
Is there a method, i can use to avoid having to set the ld_library_path?
I have a C++ project which is compiled to a universal shared library. Now, I also want a static library for the same. I tried to reuse the shared library Xcode project but the size of static library created is much smaller (~ 3MB) as compared to when I create a separate Xcode Static Library project to compile my code (~19 MB).
Here is what I tried with the shared library project:
xcodebuild -project MyLibrary.xcodeproj build MACH_O_TYPE=staticlib EXECUTABLE_EXTENSION=a GCC_ENABLE_SYMBOL_SEPARATION=NO PACKAGE_TYPE=com.apple.package-type.static-library
I don't want to maintain two Xcode project files just for compilation.
The library generated using above method works fine and is a valid static library.
xcodebuild -project MyLibrary.xcodeproj build MACH_O_TYPE=staticlib EXECUTABLE_EXTENSION=a GCC_ENABLE_SYMBOL_SEPARATION=NO PACKAGE_TYPE=com.apple.package-type.static-library
For details refer Much larger static library generated by xcode
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.