What are the proper flags to compile c code using zlib - c

I'm trying to execute the zpipe.c file from https://zlib.net/zlib_how.html
gcc zpipe.c -o executable -lz
But I'm getting the error
zpipe.c:18:18: fatal error: zlib.h No such file or directory
I installed zlib from source following this tutorial https://geeksww.com/tutorials/libraries/zlib/installation/installing_zlib_on_ubuntu_linux.php

you can use pkg-config.
pkg-config --cflags --libs zlib

Try adding -I/usr/local/include/. It could happen that you have to specify even the library's location with -L/usr/local/lib/.

Related

GTK header files not found when compiling c code in arch linux

I am attempting to compile code using the <gtk/gtk.h> header file using gcc. Whenever I do so I get the following error:
gtk.c:3:10: fatal error: gtk/gtk.h: No such file or directory
3 | #include <gtk/gtk.h>
^~~~~~~~~~~
I have looked in /usr/include/ and found gtk-1.2 gtk-2.0 and gtk-3.0 all of which have the header files within them necessary to compile the program I'm unsure why GCC can't find those files and how to reroute gcc to find the necessary header files.
GCC doesn't know which version you want to use. GTK recommends using pkg-config to compile programs. For example, for GTK 3 use:
gcc `pkg-config --cflags gtk+-3.0` yourprogram.c -o yourprogram `pkg-config --libs gtk+-3.0`
You could also specify the correct include and library paths yourself.

C compile error - #include "cmakeconfig.h" - No such file or directory

On a Linux Mint 64bit system using gcc
I'm trying to compile the MiniBrowser example included with the WebKit package that I downloaded. webkitgtk-2.22.3
I have successfully setup the WebKit library, but when I try to compile the Tools/MiniBrowser example I get the error message given in the question title.
NOTE: There is no file on my system called cmakeconfig.h
NOTE: There are a few files called CMakeLists.txt that I do not know what to do with.
NOTE: Compiled using:
gcc `pkg-config --cflags gtk+-3.0 webkit2gtk-4.0 gstreamer-1.0` -o main main.c `pkg-config --libs gtk+-3.0 webkit2gtk-4.0 gstreamer-1.0`
As per the question comments. Use the Linux command cmake with the argument CMakeLists.txt which hopefully will generate the file cmakeconfig.h
$ cmake CMakeLists.txt

undefined reference to gzdopen, gzclose, gzread

I have compiled and installed the 2.2.7.2 version of libxml. While compiling, I have this error: Makefile:755: recipe for target 'install-data-local' failed. But the lib files are correctly generated (libxml2.a and libxml2.so).
I'd like to use libxml2 in a C project so I edited my makefiles in order to integrate lib files (libxml2.a and libxml2.so).
The problem is that when I compile my project I get the followings errors:
/libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzdopen'
/libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzclose'
/libxml2.a(xmlIO.o): In function xmlGzfileRead': undefined reference togzread'
...etc
It seems that I have to install the zlib library in order to resolve this linker errors. I installed the zlib library and edited the LD_LIBRARY_PATH in order to add the path where are the zlib libraries.
I recompiled my project, but I still always having the same linker errors.
Would you please help me to resolve those linker errors.
Regards.
See the libxml2 FAQ:
Troubles compiling or linking programs using libxml2
Usually the problem comes from the fact that the compiler doesn't get the right compilation or linking flags. There is a small shell script xml2-config which is installed as part of libxml2 usual install process which provides those flags. Use
xml2-config --cflags
to get the compilation flags and
xml2-config --libs
to get the linker flags. Usually this is done directly from the Makefile as:
CFLAGS=`xml2-config --cflags`
LIBS=`xml2-config --libs`
On my current system, the output from xml2-config --libs is
-lxml2 -lz -lpthread -licucore -lm

DLL: File format not recognised when compiling C with MinGW on Linux for Windows

I'm using MinGW on Linux (Ubuntu, specifically) to compile a C program for Windows. I'm using a library called SFML, and it's bindings called CSFML. I'm using -L and -l to locate the libraries, but when I compile I get this error:
win32/dll/csfml-audio-2.dll: file not recognized: File format not recognised
I've got no idea why. Here's the command I'm using to compile:
sudo i686-w64-mingw32-gcc -o wandering src/main.c src/constants.c src/Display/display.c **...some more c files in here...** src/Generation/perlinnoise.c $(pkg-config --libs --cflags glib-2.0) $(pkg-config --libs --cflags gee-1.0) -Iwin32/CSFML-2.1/include -Lwin32/dll -lcsfml-audio-
Does anyone know why it's happening? I can compile C programs without SFML but with MinGW just fine...
The DLL has a PE32 executable file header. It's not used for the linker. You should use the import library instead. This file has the extension LIB.
I heard there are some gcc compiler versions out there than generate an import library from a DLL on the fly. It looks like your version doesn't.
From command line it seem's trying to use sudo i686-w64-mingw32-gcc 64 bit compiler and supplying 32 bit DLL i.e. win32/dll/csfml-audio-2.dll. change to x64/dll/csfml-audio-2.dll. It should work fine.

Cross-compiling for ARM while linking to libssh - libssh.so: file not recognized

I want to know if it is possible to link my application to libssh while cross-compiling with Sourcery toolchain for ARM. My host system is Ubuntu x86_64
:~/c/ssh$ arm-none-linux-gnueabi-gcc ssh.c -o arm `pkg-config --cflags --libs libssh`
cc1: warning: include location "/usr/local/include" is unsafe for cross-compilation [-Wpoison-system-directories]
/home/user/CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.1/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/usr/local/lib/libssh.so: file not recognized: File format not recognized
collect2: ld returned 1 exit status
My application compile fine with gcc using this command:
gcc ssh.c -o ssh -lssh
Adding the same -lssh flag while cross-compiling result in the following error:
:~/c/ssh$ arm-none-linux-gnueabi-gcc ssh.c -o arm -lssh
ssh.c:2:49: fatal error: libssh/libssh.h: No such file or directory
compilation terminated.
Your first attempt is trying to link the libssh.o from your host environment instead of your target environment. This is because the command "pkg-config --cflags --libs libssh" returns the package configuration of libssh on your host machine.
You will need to obtain or compile up a copy of libssh specifically for the target environment (ARM).
If compiling it yourself (likely your only option, for me at least a quick google did not reveal any suitable pre-built package) then you should specify a separate installation directory, eg. in your home directory somewhere. This will result in separate include and lib dirs, containing the cross compiled libssh, which you can reference from your own compilation commands, eg:
arm-none-linux-gnueabi-gcc -I{includedir} -L{libdir} ssh.c -o arm -lssh
Note that libssh in turn relies on other libraries - openssl and zlib - which you also have to cross-compile.

Resources