How to off prefix cyg for dynamic libraries in mingw64 - mingw-w64

I use mingw64 in msys2
When build dynamic lib automatic add prefix cyg before target name.
How i can build libs wihtout prefix?

Related

SONAME incosistency of shared protobuf lib when building with autogen and cmake

When I build shared protobuf (Version 3.15.8) libs with autogen I get libprotoc.so.26:
./autogen.sh
./configure --enable-shared
make
When I build it with cmake I get libprotobuf.so.3.15.8.0.
cd cmake && mkdir build && cd build
cmake -Dprotobuf_BUILD_SHARED_LIBS=on ..
make
Is there a way to build libprotoc.so.26 with cmake? (How can I set the SONAME there?)
You appear to be looking for the SOVERSION property of the shared library target. As far as I am aware, there is no command-line option to affect target properties, so you would need to modify the appropriate CMakeLists.txt file. You'll need to identify the CMake target name chosen for the library (a characteristic of the project, not of CMake itself), say "protobuf_lib". You would then add a command of the form
target_set_properties(protobuf_lib
PROPERTIES SOVERSION 26)
Alternatively, if there is already a target_set_properties command for the target in question, you could add the SOVERSION 26 to the property list in that command.

CMake - Compile in Linux, Execute in Windows

I have a large codebase with Linux dependencies, and I would like to use CMake to compile my code into an executable that can be run on Windows, i.e. I want CMake to produce an ".exe" file or something of that nature.
I have tried using the solution provided on the CMake website: https://cmake.org/cmake/help/v3.4/manual/cmake-toolchains.7.html#cross-compiling
however it has not worked...
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(myProject VERSION 1.0 LANGUAGES C CXX)
set(CMAKE_CROSSCOMPILING true)
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10.0)
set(CMAKE_SYSTEM_PROCESSOR arm)
find_package(... *all my required packages* REQUIRED)
include(... *required include files*)
add_executable(${PROJECT_NAME} ...)
target_link_libraries(${PROJECT_NAME} ...)
It compiles and will execute on Linux, however I want it to produce a Windows compatible executable.
You need a mingw-w64 toolchain in Linux to do this, for example on Arch Linux you can get all the necessary mingw-w64-... packages through AUR, including mingw-w64-cmake. These packets should get you going:
mingw-w64-binutils-symlinks
mingw-w64-gcc
mingw-w64-cmake
Install others to fulfill any dependencies of your software.
Then you can just run mingw-w64-cmake instead of cmake using your regular CMakeLists.txt. E.g.:
mkdir build-mingw; cd build-mingw
x86_64-w64-mingw32-cmake ../
make
However typically it is a good idea to use a static build so your executable will work standalone. Here is how I do it:
# STATIC stuff (Windows)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(BUILD_FOR_WIN TRUE)
endif()
option(STATIC_BUILD "Build a static binary." ${BUILD_FOR_WIN})
if (STATIC_BUILD)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" CONFIG)
set(BUILD_SHARED_LIBS OFF)
endif()
Which creates a variable, STATIC_BUILD, that the user can set, and is defaulted to ON if compiling for Windows.
There is not much more you need to adapt in your CMake files. For example I need to include extra Qt platform plugins when building Qt:
if (STATIC_BUILD AND ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
# include plugins into static build on windows
# (we lack support for static on other platforms right now)
set(QT_PLUGINS SvgIcon WindowsIntegration WindowsVistaStyle)
endif()
The key takeaway here for you is first to get the proper environment on your system.

CMake installs to bin/lib but app can't find lib

I'm building a multi-binary project with cmake and deploying in Debian. CMakeLists.txt reduces down to something like this:
add_library(mylib SHARED lib.cpp) #creates libmylib.so
add_executable(myapp main.cpp)
target_link_libraries(myapp my-lib)
install(TARGETS mylib myapp
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
)
If I install this to (-DCMAKE_INSTALL_PREFIX=/usr) then I have no problem. But if I install to somewhere else like (-DCMAKE_INSTALL_PREFIX=/opt/myapp, or even -DCMAKE_INSTALL_PREFIX=/usr/local), then I have a problem.
When I run $ /opt/myapp/bin/myapp my application can't find the .so.
I could deploy a script with myapp which sets:
#!/bin/sh
export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$LD_LIBRARY_PATH
exec ${CMAKE_INSTALL_PREFIX}/bin/myapp $*
But this feels like a hack. Plus, the script would need to be generated at configure time with ${CMAKE_INSTALL_PREFIX}/lib.
I imagine that there's a more native way to handle this which lets me simply execute my application from /opt or /usr/local after installation. It would preferably handle this at configure, compile, or install time instead of just before runtime and preferably wouldn't require someone to modify their ~/.bashrc or ~/.profile.
Could you please tell me if there is some way to deploy the standard bin,lib structure in linux to arbitrary paths without the need for pre-runtime scripting?
You should:
use rpath (Unix) or loader_path (MacOS)
or install it in regular system path (/usr/lib or /usr/local/lib etc...)
or use LD_LIBRARY_PATH.
Example to set RPATH:
if(APPLE)
set(CMAKE_INSTALL_RPATH "#loader_path/../lib;#loader_path")
elseif(UNIX)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
endif()
note: on macos you should now use #rpath
note2: on macos you can use otool -l and otool -L to introspec.
note3: you can use ldd lib.so and objdump -p lib.so on GNU/Linux.
Note: Prefer to use GNUInstallDirs
include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

Cabal don't find relative library for compilation of gsasl package

I'm using Haskell on webfaction server, with non root access, on a CentOS 6 system.
I have a /lib/ folder which contain libraries.
Actually, i have a problem with some libraries needed for an installation of package using cabal install.
I need the libgsasl library installed, so i download and compile the gsasl package from sources :
I wget the latest tar.gz here
I run ./configure --prefix=$HOME to install compiled libraries into $HOME/lib
i make and make install
Next, i try two way with cabal install gsasl command, which actually fails :
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
cabal install gsasl --bindir=$HOME/bin --extra-include-dirs=/home/reyman64/lib/ --extra-lib-dirs=/home/reyman64/lib
Any of the command found the good libraries ...
The pkg-config package 'libgsasl' version superior to 1.1 is required but it could not be found.
So i verify, my version is 1.8, and i have the libgsasl.sa .la .so .so.7 .so.7.9.6 in $HOME/lib and i have a libgsasl.pc into $home/lib/pkgconfig
Any idea of the problem ?
Make sure your PKG_CONFIG_PATH environment variable is set to include $HOME/lib/pkgconfig, i.e. the directory where you've placed libgsasl.pc.

GCC 4.7.2 requires ppl?

I'm trying to configure GCC 4.7.2, but it's failing with configure: error: Unable to find a usable PPL
I've looked in GCC prerequisites page and PPL isn't mentioned anywhere.
I'm using CLooG 0.17.0, which uses ISL, and as such no longer requires PPL (as far as I can tell)
Is there some other requirement on PPL in GCC which means I still need PPL, or am I missing some flag from my configure line?
I am passing the following options to configure:
--enable-cloog-backend=isl
--with-cloog=$PREFIX
--with-isl=$PREFIX
--with-gmp=$PREFIX
--with-mpfr=$PREFIX
--with-mpc=$PREFIX
For completeness, my full configure line is as follows:
./configure --prefix=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64 \
--disable-multilib --enable-cloog-backend=isl \
--with-mpc=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64 \
--with-mpfr=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64 \
--with-gmp=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64 \
--with-isl=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64 \
--with-cloog=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64 \
--build=x86_64-suse-linux --with-pkgversion='SIG build 11/27/2012' \
--with-gxx-include-dir=/hostname/tmp/syddev/sdk/gcc472/suse11/x86_64/include/c++/4.7.2 \
--enable-version-specific-runtime-libs
Update:
In order to try make forward progress I decided to add PPL to my installation list, and add --with-ppl=$PREFIX to my configure line.
Configure still fails with configure: error: Unable to find a usable PPL
It seems this is a bug in the configure script: Configure fails if PPL_MINOR_VERSION < 11
With the latest version PPL_MINOR_VERSION=0 (and PPL_MAJOR_VERSION=1)
The GCC Prerequisites page jumped the gun and is showing the prerequisites for GCC 4.8.
GCC 4.7.2 still uses PPL instead of ISL, as evidenced by the lack of --with-isl=PATH in the output of configure:
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-build-libsubdir=DIR Directory where to find libraries for build system
--with-mpc=PATH specify prefix directory for installed MPC package.
Equivalent to --with-mpc-include=PATH/include plus
--with-mpc-lib=PATH/lib
--with-mpc-include=PATH specify directory for installed MPC include files
--with-mpc-lib=PATH specify directory for the installed MPC library
--with-mpfr-dir=PATH this option has been REMOVED
--with-mpfr=PATH specify prefix directory for installed MPFR package.
Equivalent to --with-mpfr-include=PATH/include plus
--with-mpfr-lib=PATH/lib
--with-mpfr-include=PATH
specify directory for installed MPFR include files
--with-mpfr-lib=PATH specify directory for the installed MPFR library
--with-gmp-dir=PATH this option has been REMOVED
--with-gmp=PATH specify prefix directory for the installed GMP
package. Equivalent to
--with-gmp-include=PATH/include plus
--with-gmp-lib=PATH/lib
--with-gmp-include=PATH specify directory for installed GMP include files
--with-gmp-lib=PATH specify directory for the installed GMP library
--with-host-libstdcxx=L use linker arguments L to link with libstdc++ when
linking with PPL
--with-stage1-ldflags=FLAGS
linker flags for stage1
--with-stage1-libs=LIBS libraries for stage1
--with-boot-libs=LIBS libraries for stage2 and later
--with-boot-ldflags=FLAGS
linker flags for stage2 and later
--with-ppl=PATH specify prefix directory for the installed PPL
package. Equivalent to
--with-ppl-include=PATH/include plus
--with-ppl-lib=PATH/lib
--with-ppl-include=PATH specify directory for installed PPL include files
--with-ppl-lib=PATH specify directory for the installed PPL library
--with-cloog=PATH Specify prefix directory for the installed CLooG-PPL
package. Equivalent to
--with-cloog-include=PATH/include plus
--with-cloog-lib=PATH/lib
--with-cloog-include=PATH
Specify directory for installed CLooG include files
--with-cloog-lib=PATH Specify the directory for the installed CLooG
library
--with-build-sysroot=SYSROOT
use sysroot as the system root during the build
--with-debug-prefix-map='A=B C=D ...'
map A to B, C to D ... in debug information
--with-build-config='NAME NAME2...'
use config/NAME.mk build configuration
--with-build-time-tools=PATH
use given path to find target tools during the build
It's unfortunate that they don't maintain prerequisites pages for versions prior to 4.8.

Resources