Building/Linking libgcrypt for Mingw - c

I'd like to implement some features of libgcrypt in my program, but it is currently running on Windows, OSX, and Linux (Arch/Xubuntu), so I can only really do so if I can build it for all three platforms. On OSX and Linux I had no problem.
I got the sources from the github page for libgcrypt and libgpg-error, and I've successfully built and run the libraries on both Linux and OSX, so I know that my test code is valid (which I am now having trouble with on Windows w/MinGW).
I did the following on Xubuntu (and similar on Arch but using pacman instead of apt-get):
sudo apt-get install mingw32 mingw32-runtime mingw32-binutils
to get the cross compiling tool chain and
git clone https://github.com/Chronic-Dev/libgcrypt.git
git clone https://github.com/Chronic-Dev/libgpg-error.git
cd libgpg-error
autoreconf -vfi
./autogen.sh --build-w32
make
sudo make install
cd ../libgcrypt
autoreconf -vfi
./autogen.sh --build-w32
make
sudo make install
to build, and it successfully builds these files in home/myuser/w32root/:
libgcrypt.a
libgcrypt.def
libgcrypt.dll.a
libgcrypt.la
libgpg-error.dll.a
libgpg-error.la
include/
gcrypt.h
gcrypt-module.h
gpg-error.h
I took these files over to windows, and tried compiling the test code (named main.c locally) with
gcc main.c -o main.exe -lgcrypt
but I get undefined reference errors leading me to the conclusion that the library wasn't linked correctly (initially only using libgcrypt.a), so I looked some stuff up, and found that some libraries require a set of files like .a, .def, et al. to work, so I dropped them all in C:\Mingw\lib to see if it made a difference; it didn't. The following was also silent in finding the library file to link, but didn't resolve the undefined references:
gcc main.c -o main.exe -lgcrypt -lgpg-error
So I'm not really sure where to go from here. The readme doesn't get into cross compiling too much, like what files to copy and link once you're on the Windows side. Any pointers (to docs for it I missed maybe?) are appreciated! Thanks a bunch for reading my wall of text.

Related

error when compiling testfiles from installed c-algorithms library

I'm trying to install and test c library c-algorithms from Github.
https://github.com/fragglet/c-algorithms/blob/master/test/test-queue.c
When I try to test the installation from the generated test folder with:
gcc -o test-arraylist `pkg-config --cflags --libs libcalg-1.0` test-arraylist.c
I get the following error massage:
test-arraylist.c:30:23: fatal error: arraylist.h: No such file or directory
compilation terminated.
I use a Vagrant box: ubuntu/xenial32 with Ubuntu 14.04.5 LTS
Prior to installation of c-algorithms:
sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install pkg-config
To install the library I have done following:
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
Any help would be highly apriciated
The test-arraylist.c has line #include "arraylist.h" but it is under the libcalg subdirectory not directly in the include path.
libcalg subdir should be added to the include path or you have to modify the include like #include "libcalg/arraylist.h"
If you want only run the tests, then run the
sudo make check from the build root (in your case it is the source root)
This is probably going to be stomped on by process-fetishizers.
But.
When you build in a Unix/Linux operating system (and derivatives like RTEMS), you are building off other people's libraries - so you need those libraries and their header files ( just like c-alg... ) installed in locations that your compiler can find.
To find a file that is associated with a package, use dpkg as explained here:
https://askubuntu.com/questions/481/how-do-i-find-the-package-that-provides-a-file
But you have another problem you might not be aware of. You are trying to compile a test program using a gcc command when the software uses GNU autoconf automake and probably libtool to function PROPERLY.
Perhaps you don't understand you need to make sure autoconf, automake, and then libtool find the right configuration from one directory system to another. Fedora puts files in differing spots from Ubuntu distros.
Instead run:
autoreconf -fvi
first in the top level directory and see if this finds your header file.
THEN you run
./configure
and then
make test/check
(whichever it uses, some use recipe "all-tests", etc.)
make all
This would make all if your system is ready to handle them.

libwebsockets.h - no such file or directory, Ubuntu, arm-linux-gcc cross compiler

I am building a web server using the libwebsockets library on a TS-7800 board using the arm-linux-gcc cross compiler. Using Ubuntu. Installed CMake, OpenSSL, and libwebsockets and built the library per the instructions on Github.
I made a "hello world" C file which #includes libwebsockets.h
When I compile the executable with gcc, it compiles fine and the .exe runs.
When I compile with arm-linux-gcc, I get the following:
root#gordon-MS-7A39:/# arm-linux-gcc -o hellosockets /home/gordon/workspace/HelloCrossWorld/hello_cross.c
/home/gordon/workspace/HelloCrossWorld/hello_cross.c:3:27: libwebsockets.h: No such file or directory
It appears that arm-linux-gcc compiler cannot "see" the header file for libwebsockets. I'm guessing that the installation of the websockets library was successful because gcc can see it.
How do I enable the arm cross compiler to see the libwebsockets.h file?
Thank you for your input!
You'll need to add armhf architecture to your package management system. Perform the following actions as super user:
dpkg --add-architecture armhf
apt update
apt install libwebsockets-dev:armhf
Make sure you're also using the armhf toolchain:
apt install binutils-arm-linux-gnueabihf g++-arm-linux-gnueabihf
Alternatively, take a look at Buildroot
I was unaware of the -I and -L preprocessor options for gcc and arm-linux-gcc.
I was able to add libraries to the project and will look into creating makefiles for the project.

How to handle problems with RPATH on Mac OS X while installing cmocka?

I am trying to install and run cmocka library for unit testing on Mac OSX Yosemite 10.10.3, but I've got some problems with the RPATH settings.
Update:
Thanks to #baf, I was able to include cmocka.h in my CMakeLists.txt manually like this:
set(CMAKE_C_FLAGS_DEBUG "-I/usr/local/include/cmocka.h")
However, why is it so that I have to do it manually?
I've already tried many different ways of installing it:
What I've done so far:
Download cmocka from here: here. Version 1.0.
tar xvf cmocka-1.0.1.tar.xz
cd cmocka-1.0.1, mkdir build and cd build
sudo cmake ..
I get a message like this here:
-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake --help-policy CMP0042" for policy details. Use the cmake_policy command to set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
cmocka_shared
This warning is for project developers. Use -Wno-dev to suppress it.
Question #1: How can I set the rpath so that there is no warning like the one above?
sudo make
sudo make install
cmocka should be installed now, right?
Running cmake for my program which is using cmocka library.
So now I run cmake for my program and my main CMakeList.txt file has lines like this:
find_library (CMOCKA cmocka)
if (NOT CMOCKA)
message (WARNING "Cmocka library not found.")
endif (NOT CMOCKA)
But the warning doesn't show up during this phase, so I believe that find_libarary(CMOCKA cmocka) has successfully located cmocka on my computer.
Running make for my program.
While running make I get an error like this:
fatal error:<br>
'cmocka.h' file not found<br>
#include <cmocka.h>
^
1 error generated.
So I guess that cmocka cannot be found...
Question #2: Why cmocka library cannot be found?
Additional notes:
I've tried running
$ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
but it didn't helped. I guess it is a solution for Linux, not Mac.
I've tried to learn something about RAPTH on Mac in cmake from their official documentation here: http://www.cmake.org/Wiki/CMake_RPATH_handling. However I understood very little and I wasn't able to come up with a solution for my problem.
I've tried installing cmocka using brew but I got the same result.
Moreover, I've read many questions at SO about RPATH, linking and cmocka, but I couldn't find a suitable solution as well. Nevertheless, here is the list of related threads:
How to set the runtime path (-rpath) of an executable with gcc under Mac OSX?
https://stackoverflow.com/questions/29721183/getting-undefined-symbols-for-architecture-x86-64-when-trying-to-build-on-osx
How to configure scons to link using rpath on mac?
mariadb install failure: make (Mac OSX 10.6.8)
I've run otool -L cmocka. Here's what I got:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: can't open file: cmocka (No such file or directory)
I was able to successfully compile my program (thanks to baf) when I added the -I/usr/local/include flag to my debug flags:
set(CMAKE_C_FLAGS_DEBUG "-std=gnu99 -Wall -pedantic -g -I/usr/local/include/cmocka.h")

linking clang address sanitizer on FreeBSD 10.1 Release

I'm trying to get address sanitizer working on FreeBSD 10.1 Release, but whenever I try to compile a program with -fsanitize=address I get undefined references to _asan_stack_malloc_1 etc, etc. I found
https://forums.freebsd.org/threads/gcc-clang-address-sanitizer.47985/ on google but the suggestion of adding -L/usr/local/lib -I/usr/local/include didn't resolve the linking issue. I tried the llvm binaries for FreeBSD but when I go to compile with that clang I get /usr/bin/../lib/clang/3.6.0/lib/freebsd/libclang_rt.asan-x86_64.a , no such file or directory. . Either way I'm not sure what library I need to link or where it is.
Below is the program I tried compiling and here is the command I used,
clang -fsanitize=address san.c
#include <stdio.h>
int main(void)
{
return 0;
}
As an alternative to building LLVM, as suggested in this answer on Unix SE, you can install llvm37 from ports, which supports AddressSanitizer, and build with that:
# pkg install llvm37
$ clang37 -fsanitize=address san.c
To use asan on FreeBSD you can build llvm with asan support as shown below or you can install from packages/ports like in Kevinoid's answer.
Step one, grab the latest stable llvm source.
fetch http://llvm.org/releases/3.9.0/llvm-3.9.0.src.tar.xz
Now uncompress the llvm source directory.
tar -xvf llvm-3.9.0.src.tar.xz
Next change directory to llvm and grab the clang source files.
cd llvm-3.9.0.src/tools && fetch http://llvm.org/releases/3.9.0/cfe-3.9.0.src.tar.xz
Uncompress clang.
tar -xvf cfe-3.9.0.src.tar.xz
Enter the projects directory and grab compiler-rt.
cd ../projects && fetch http://llvm.org/releases/3.9.0/compiler-rt-3.9.0.src.tar.xz
Uncompress compiler-rt.
tar -xvf compiler-rt-3.9.0.src.tar.xz
Goto the root llvm directory and make a build directory for cmake.
cd ../ && mkdir build && cd build
Use cmake to setup the llvm build.
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON [-DLLVM_ENABLE_WERROR=ON] [-DLLVM_TARGETS_TO_BUILD=X86] -DBUILD_SHARED_LIBS=ON ../
Build llvm and go grab some tea, it will take a bit.
make -j12
If the build worked you should be left with clang with asan support. Make sure to remove the old compiler, /usr/bin/clang, /usr/bin/clang++ and /usr/bin/cc.
Then install the new clang by doing sudo make install. Finally you will probably want to link /usr/bin/cc to /usr/local/bin/clang by running sudo ln /usr/local/bin/clang /usr/bin/cc.
After doing all these steps you should be able to compile code with the -fsanitize=address compile option.

Issue Statically Compiling Thrift 0.9.0 on Centos 6.5

I'm working to compile the Thrift 0.9.0 binary statically in a CentOS VM. I get the issue that the libthrift.a binary is not being created. I am using a vagrant box to run centos:
https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
Once I ssh to the vagrant box I run the following commands:
wget https://archive.apache.org/dist/thrift/0.9.0/thrift-0.9.0.tar.gz
tar -zxvf thrift-0.9.0.tar.gz
cd thrift-0.9.0
./configure --enable-static
make
This will run but I ran a find command (sudo find / -name "*.a") on the system to see if there was any ".a" files made and the only file that was made was "libparse.a" which doesn't seem right. From my understanding it should be "libthrift.a".
Searching through the config.log file it says that it does want to build the static libraries:
configure:11944: checking whether to build static libraries
configure:11948: result: yes
Looking at more locations in the log file that has the keyword "static" reveals potential places that may be errors.
configure:9028: checking if gcc static flag -static works
configure:9056: result: no
configure:13915: checking if g++ static flag -static works
configure:13943: result: no
lt_cv_prog_compiler_static_works=no
lt_cv_prog_compiler_static_works_CXX=no
The full log file is here: http://www.filehosting.org/file/details/449460/staticThriftErrorLog.rtf
Any help is appreciated
I was able to generate the libthrift.a file. After running the command for the extra dependancies mentioned in my comment I forgot to run the make command. So after doing the make command I found the libthrift.a file in "thrift-0.9.0/lib/cpp/.libs/". Interestingly enough, even after fixing the dependencies, config.log still had the same potential problem areas regarding the gcc/g++ static flag and static compiler.
Specifically the dependency command is as follows:
sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel.x86_64
Edit: After getting advice on the Jira ticket, it turns out the specific vagrant box I was using was causing the errors. Using the VM he linked I was able to successfully build Thrift using the provided instructions. (Jira ticket https://issues.apache.org/jira/browse/THRIFT-2559)

Resources