Use Xcode Shared Library Project for Static Library - c++

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

Related

Static libraries in Qt 5.14 MinGW toolchain? (default Qt installation)

Just now I noted that the MinGW Toolchain that comes with the default Qt installation, at least Qt 5.14, comes with a lib directory with libQt5*.a files. Are those files static libraries?
I think so because:
They have a size similar to the ones that I get when I compile Qt statically for release.
$file ./libQt5Core.a outputs ./libQt5Core.a: current ar archive, which is the same that it outputs for the statically compiled ones.
If indeed they're static libraries, how can I tell QMake (for example editing the .pro file) to link to those instead of linking to the shared ones?
Are those files static libraries?
No. They are not static. Qt’s default online installer provides only shared libraries. That *.a files are so-called import libraries.
Import library is an .a or .lib library, but it only contains bit of information needed to tell the linker/OS how your program interacts with the dll’s.
If you need Qt static windows build for some reasons, you have some options:
HARD Build whole Qt (or needed modules) by yourself.
EASY Use vcpkg: vcpkg install qt5:x64-windows-static
With vcpkg you can create custom MinGW triplet if you need MinGW for some reason. But I suggest you stick with MSVC.

How to build static libraries and linkthem to a c++ project in linux platform?

I am working on a text-classification project, which is big and doesn't use bazel as its build tool. I want to integrate tensorflow into my project, but I find it is hard to change my build tool to bazel. So I wish to build static libraries on tensorflow and link them into my project.
Does anyone know how to build standalone static libraries on tensorflow source and link them in the existing c++ project? Thanks a lot.
The TensorFlow repository has some Makefiles you can use to build a static library (see tensorflow/contrib/Makefile).
Alternatively, you could use bazel to build the TensorFlow C++ shared library and then load and use the shared library in your application (bazel build -c opt //tensorflow:libtensorflow_cc.so). Unfortunately, bazel can't yet produce a static library (#1920).
Hope that helps.

Error building Static Library with OpenCV and Xcode on C++

I'm trying to build a DLL library for Unity3D (in 32-bit) but first of all I want to make a .a static library to make a C++ Wrapper for C#.
Well, this is what I've done.
I've built OpenCV unchecking BUILD_SHARED_LIBS in order to get the STATIC LIBS, with architecture i386.
I've made my static library code and built it, Linking the static libraries that I needed (I really import them all because I'm having errors and I want to know if it's an error lib-based):
(included from /lib/ and /3rdparty/lib/)
I'm linking my library and header in a new project (Command Line Tool) in order to test my new static library, but my errors are:
(pastebin link)
Well, I have no idea what's wrong.
This is my settings on the static library:
This is my settings on my test Command Line Tool (for testing my library)
Does anyone have idea about this?
Thank you very much in advance.
Regards.
EDIT: tried to manipulate the static libraries for 64 bits as well but nothing happened.
The solution was removing several paths on the Library paths since it was messing up some libraries.

How can I use boost::test with xcode 4 for testing some ios c++ code?

I would like it to operate similarly to how the normal test framework works - if you the tests from the Product->Run tests menu item, the output should appear in the left sidebar window.
I found a guide for using xcode 3 with boost test, but couldn't figure out how to translate those instructions for xcode 4 (if it is even possible).
Finally, I'm building an iPhone application. I could get boost running using the #include <boost/test/included/unit_test.hpp>, however it is pretty slow. Using the standard #include <boost/test/unit_test.hpp> results in link errors due to the library being built for the wrong architecture.
You should build the boost library to a static library ".a" using .configure and make.
According to this:
No special build options or macro definitions are required to build
the static library. Using the Boost.Build system you can build the
static library with the following command from libs/test/build
directory:
bjam [-sTOOLS=] {-sBUILD=boost_unit_test_framework}
This library or libraries and their respective headers need to be added to the project. (Two built versions are needed, one i386 for the simulator and one ARM for devices).
The static library is imported from Link Binary with Libraries in
Build Phases.
Also you need to tell XCode which of these to use, you
can do this by setting contidional build settings in `Build settings-
Library search paths. Above this line is where you add the Header
Search Path to the boost header files.
After this you should be able to include the headers (Added above) in C++ or objective-C++ code of yours. (To make Obj-C files Obj-C++ files you need to change all deppendent .m files to .mm)
If there is a some problems after this, switching Compiler or standard library for C++ in Build Settings might help.

Linking to a library that links to a library

I'm trying to link cpgui to my library, which links to SFML. I use code::blocks so I had to make my own project for that library, and as it requires SFML I statically linked to SFML in that library and compiled it fine.
Now, when I attempt to statically link that library to my library, I get a bunch of undefined references to SFML when I compile my project. Even if I linked to SFML in both projects, what's happening?
As you guessed, you can make it simpler by adding the library files directly to the project.
Another solution as suggested by AJG85 would have been to link the library -- after taking care of conflicting dependencies.
Use relevant documentation as suggested by answer to How do I link a library to my project in CodeBlocks & GCC without adding the library source to my project