How to use WAF with a MacPorts installation - macports

I have a project with uses WAF (not a project I originated). Some people are going to compile the project on Windows, others on Linux, some on OS X. Those compiling on OS X might use MacPorts, others use Homebrew, others might use custom compiled libraries installed in /usr/local.
I'd rather not hard-code paths such as /opt/local into wscript. What's the best practice for supporting all these different package managers on OS X? I'm just starting to learn about WAF, BTW. Is there a --prefix or some other option that allows WAF to look in /opt/local for headers and libs? Should all users who are compiling the project be required to set environment variables such as:
export LIBRARY_PATH="/opt/local/lib"
export LDFLAGS='-L/opt/local/lib'
export CPPFLAGS='-I/opt/local/include'
export LD_LIBRARY_PATH=/opt/local/lib
export LD_INCLUDE_PATH=/opt/local/include

Related

How to use C library installed with vcpkg on linux?

I'm trying to install libwebsockets C library with vcpkg according to the instruction. And don't understand something.
OS - Ubuntu 20.04
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install [library-name]
Library is installed and what to do next? How to compile test files with the library?
The question is more about how to use vcpkg on linux.
You can give an example of another library installed with vcpkg.
vcpkg is a C/C++ package manager, it is very necessary in windows.
However, in ubuntu, itself provides a very complete package management mechanism.
Therefore, even if you are building a cross platform software system, do not use vcpkg in ubuntu :)
You can try this:
$> sudo apt install libwebsockets-dev
In this way, the libwebsockets header files and library files you need have been installed and can be used directly.
Here is another example:
I want to install gtkmm4 in ubuntu 20.04 LTS, since gtkmm4 is not available for apt download I'm installing it with vcpkg.
for simplification, I'm setting VCPKG_DIR to the vcpkg directory I cloned.
export VCPKG_DIR=/path/to/vckpg
Then for a C++ program, you can write CMake file like below
PROJECT(gtkmmtest)
cmake_minimum_required(VERSION 3.10)
set(VCPKG_DIR $ENV{VCPKG_DIR})
include(${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake) # --> important
# Use the package PkgConfig to detect GTK+ headers/library files
FIND_PACKAGE(PkgConfig REQUIRED)
FIND_PACKAGE(Threads REQUIRED)
pkg_check_modules(GTK4 REQUIRED gtk4)
PKG_CHECK_MODULES(GTKMM gtkmm-4.0)
include_directories(${GTK4_INCLUDE_DIRS})
include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${VCPKG_DIR}/packages/gtk_x64-linux/lib)
link_directories(${GTK4_LIBRARY_DIRS})
add_definitions(${GTK4_CFLAGS_OTHER})
target_link_libraries(${GTKMMTEST} PRIVATE ${GTK4_LIBRARIES} ${GTKMM_LIBRARIES} pthread)
Complete CMake file can be found here
You can still use the the standard include_directories and link_directories if there is no PkgConfig avilable.
eg:
include_directories(${VCPKG_DIR}/packages/gtkmm_x64-linux/include/gtkmm-4.0/)
Library is installed and what to do next? How to compile test files with the library?
The question is more about how to use vcpkg on linux.
The answer to this question really depends on your buildsystem and the port/library you want to use and not the platform itself.
In the case of libwebsockets libwebsockets-config.cmake get installed so you could use CMake and do a find_package(libwebsockets CONFIG REQUIRED) to get the imported targets the port exports within LibwebsocketsTargets.cmake. Of course this requires setting CMAKE_TOOLCHAIN_FILE to the vcpkg toolchain (<vcpkg_root>/scripts/buildsystems/vcpkg.cmake) or including it before the first project() in your CMakeLists.txt (more details are mentioned in the vcpkg docs which you hopefully read....)
Other libraries/ports might export *.pc files. For these FindPkgConfig.cmake can be used directly (see CMake docs) or you can setup PKG_CONFIG_PATH and prepend <vcpkg_root>/installed/<triplet (here probably: x64-linux)>/(debug/)lib/pkgconfig for other buildsystems like autotools or manual makefiles etc.
In the end how to use vcpkg or more precisly the libraries from it depends on what buildsystem you intend to use.

Linker directory for Qt5

I want to run an application based on Qt5 shared objects.
Although I have apt installed qt5-default, qttools5-dev and qttools5-dev-tools I get the error bellow:
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.7' not found
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5' not found
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: version `Qt_5' not found
/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5: version `Qt_5' not found
I have also tried to change some environment variables as LD_LIBRARY_PATH and DYLD_LIBRARY_PATH, resulted in no success!
What do you suggest?
When you built your application, which version of Qt5 did you build against? You can see this in QtCreator by looking at the currently selected kit:
If you just installed QtCreator from binary, it is shipped with it's own set of Qt5 shared libraries that your application is linked against, however your OS' version of those libraries (those installed from apt-get and similar) may not match.
When you try to run the application on it's own outside QtCreator, it may try to link against the OS version of the libs which are usually much older.
There are many ways to resolve this. One way, which would be preferred if you don't care for the newest version of Qt, is simply building towards the Qt libs supploed by the OS. You can do this by creating a new kit that specifies to build against the OS' libraries following this procedure.
Another way is shipping the shared libraries that you used from QtCreator together with the application so that those will override the OS ones. Usually just chucking them into the same folder as the executable will do the trick, as they will be found before the ones under /usr/lib/whatever etc.
Yet another way is to build your own static version of Qt and link with that. This has some benefits and some drawbacks. This is an advanced topic, so I won't go into detail (you can see here). But in this case the Qt libs are built into your app and will not depend on any external Qt libs version.

Build Cyrus SASL as static library on Windows

I need the library Cyrus SASL as a static library on Windows (https://cyrusimap.org/mediawiki/index.php/Downloads#SASL_Library)
How to do that ?
As far as I know, you will need a MinGW and MSYS environment and then just build the SASL from sources like it were on Unix-like, i. e.
./configure
make
make install
You will get some *.a files -- those are static libraries, built with MinGW, they should work for Windows.
I'm still checking this topic, so I'll add some more info if I'm done with it.
For more reference about building projects from sources check the INSTALL file in your project's root directory, i. e. cyrus-sasl-<version>/INSTALL
upd: this seems to be not an easy thing to do, check out this article
upd2: if you prefer Visual Studio, you could check this rather outdated howto.
upd3: in general good article from GNU

Cross compile GTK+ application from Linux to Windows?

How can I cross compile my GTK+ app (written in C) from Linux to Windows? Could I just replace the "gcc" command with "mingw32"?
Fedora has a great mingw32 cross-compiler toolchain which comes with lots of precompiled libraries, including GTK+ and gtkmm. For most applications you just need to install the cross-compiler and the cross-compiled GTK+ libraries:
yum install mingw32-gcc mingw32-gtk2
Once everything needed is installed, compiling your application is just the matter of running "mingw32-configure" followed with "make".
More information at the project page https://fedoraproject.org/wiki/MinGW
You can use mingw-cross-env - all you have to do then is to change your CC/CXX environment path to use the i686-mingw32- prefix and export the mingw-cross-env bin dirs (both) to your PATH variable (or if you are using autotool it's even easier) - see the documentation on the homepage.
There is actually a project called MXE that does exactly this.
Pre-build package
You can download my pre-build binaries if you want.
Build from source
You can also build the code from scratch ideally also applying this PR to update to the latest GTK 3.24 version.
MXE has a easy wrapper (x86_64-w64-mingw32.static-cmake) to cross-build your project towards Windows, while using Linux. Allowing to evenly statically build your project into a single .exe file! Of course shared builds (x86_64-w64-mingw32.shared-cmake) are also supported. The example wrapper scripts are meant for CMake based projects.
Before you can build your project with MXE, you need to build the GTK3 from source-code. (There are some Linux packages available, but mostly out-dated). If you are using C++, you can also build gtkmm3. Since you are in place C, you only need to build gtk3.
git clone https://github.com/mxe/mxe.git
Become root user: su
mv mxe /opt/mxe
cd /opt/mxe
Build the MXE project yourself:
For static builds under Windows 64-bit for GTK3 & Gtkmm3:
sudo make gtk3 gtkmm3 -j 16 MXE_TARGETS='x86_64-w64-mingw32.static' MXE_PLUGIN_DIRS='plugins/gcc12'
For shared build to Windows 64-bit (again GTK3 + Gtkmm3):
sudo make gtk3 gtkmm3 -j 16 MXE_TARGETS='x86_64-w64-mingw32.shared' MXE_PLUGIN_DIRS='plugins/gcc12'
More info see the tutorial steps on MXE.cc.
Once you done the cross-compile environment / MXE build. Now you can use the CMake wrapper scripts I mentioned earlier. Those scripts are located in the /opt/mxe/usr/bin/ directory.
The scripts (like x86_64-w64-mingw32.static-cmake) can now be used to compile your project towards Windows, while using the Linux operating system. The build result would be an Windows .exe.
Disclaimer: I personally created this PR for MXE to update GTK to the latest 3.24.x release.

Question about Macports

I just got Macports installed on my mac, of which os version is Snow Leopard (10.6). I used Macports to install several packages through 'sudo port install' command, and all these packages are reported active after the installation. I just wonder that whether these packages are really working? For example, macports tells me that 'gcc44 #4.4.2_0 (active)', however in python it says '[GCC 4.0.1 (Apple Inc. build 5493)] on darwin'.
So I just want to know that if there is some problem with my method of installing or my macports needs some configuration after installation?
Any help is appreciated! I am really new in Mac OS.
I believe Python is declaring the version of gcc used to build it which should be the gcc installed on your Mac i.e. the version that came with the Mac OS Development tools. This should be located in /usr/bin/gcc.
You should find the gcc version matches when you execute
/usr/bin/gcc -v
I do not think anything is wrong with your setup or configuration. It just shows Python was compiled using the gcc provided by Apple
Macports installs software not to conflict with the versions provided by Apple. If they replaced the C compiler and libraries, really bad things might happen when Apple provided operating system updates.
gcc is the command for Apple's version of gcc, at /usr/bin and version 4.0.1 for Leopard.
gcc-mp-4.4 is the command for gcc version 4.4 as provided by MacPorts, located at /opt/local/bin.
Similarly there will be versions of python in /opt/local/bin.
Like houmam, I prefer to explicitly invoke versions by name. If you want to connect particular versions to python, I think that the MacPorts package python_select (this has now been replace by port select python) implements this by using symbolic links. I've never used it.
It probably is just that compiler that was picked by the build was that installed by XCode. You can try typing which gcc to see which one is in your path. The macports one would by default be in /opt/local somewhere.

Resources