compiling ImageMagick core in c - c

I am trying to compile simple imageMagick (MagickCore). I am using the C interface. The code I am trying to compile is the first example this site MagickCore API!
The configuration and installation of the library goes perfect. the "make check" command result all check to "PASS".
I also able to run operations on the command line, example:
convert logo: test.gif
Now, I want to use the C programming API. I just start with an example provided on MagickCore API!
I try to compile it using the following command: (which itself is provided on the same site as the source code):
cc -o test `pkg-config --cflags --libs MagickCore` test.c
but it results the following error (I try to look around and it is taking my time).
fatal error: MagickCore/MagickCore.h: No such file or directory
any suggestion please?
please note that I have also set the PKG_CONFIG_PATH environment variable, so ImageMagick is now in my default system path: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Try use the compiler argument -I path_to_headers, specifying the path of Magick headers (or something others).

Related

How to use the hidapi library from Signal11?

I installed the hidapi library from Signall11 on my windows10 pc (using minGW). But now I'm having some trouble actually getting it to work with gcc. I have some main.c file in which I include the hidapi.h file. My gcc command looks like
gcc main.c
I'm not sure where I'm going wrong because whenever I try to run this command I get an undefined reference error to some function that is defined in the hidapi.h file.
A full compile command for a project using hidapi is like this:
gcc -o your_app your_app.c -lhidapi-hidraw
It's not enough to include #include "hidapi.h" in the C-code, which does let gcc compile. You also need -lhidapi-hidraw to link with the library. I.e. compiling is in fact a 2 step process.

SysGCC toolchain can't find files in sysroot

I set up this toolchain on my Windows machine for my Pi (raspberry-gcc4.6.3-nosysroot.exe) and then I followed the instructions here to synchronize my sysroot.
I use a library called WiringPi in my project, and I have confirmed that it is in the synchronized sysroot:
Then I attempt to compile it:
arm-linux-gnueabihf-gcc -Wall -O -c main.c
But I get the following error:
fatal error: wiringPi.h: No such file or directory
What do I have to do to make the compiler find the header file? I thought the whole point of synchronizing the sysroot was to make this kind of thing work?
You'll have to let gcc know where to look for the include files via the -I argument. In the case above, -IC:\SysGCC\Raspberry\...\usr\local. You may have to add more than one include path, depending on where the required files are scattered. You can also try to set gcc's environment variable(s).
Finding out the correct include path can be a little tedious (see above: should it be local\ or local\include\?). Maybe you can find the environment setting for all default include paths on your Pi and just copy it over to your Windows machine.
Edit: Think I got it: echo | gcc -v -E -

How to compile C code using NDK for Android Device (ARM)?

I need to perform the following steps:
write a simple counter that keeps resetting itself after overflow in C/C++
compile and push that code into the phone via ADB
run it as a regular executable in background via ADB shell
how to compile the above C code using NDK toolchain? I found a couple of similar links but none of them give simple and complete steps to do so.
If there is a link with complete steps please do refer me to the same.
Compile Environment: Ubuntu, compile should be done via console not any IDE
You're right, I made a mistake, I had not even tested it and gave me the
same error, is due to the entry point of the "main", as this has not
changed but I hope this works for you. Anyway check the symbol table "nm",
the real-time execution "strace", you can even use gdbserver.
#include <stdio.h>
int main (int argc, char *argv[])
{
printf ("hello world");
return 0;
}
export NDK_ROOT=your_ndk_path
export PATH=$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin:$PATH
export CC=arm-linux-androideabi-gcc
export LD=arm-linux-androideabi-ld
arm-linux-androideabi-gcc -I$NDK_ROOT/platforms/android-18/arch-arm/usr/include -Wl,-rpath-link=$NDK_ROOT/platforms/android-18/arch-arm/usr/lib -Wl,-L$NDK_ROOT/platforms/android-18/arch-arm/usr/lib -Wl,-lc -o test test.c
If ld return with erros like "... ld: error: cannot open... : No such file or directory"
try this for your losed files:
ln -s $NDK_ROOT/platforms/android-18/arch-arm/usr/lib/crtend_android.o
ln -s $NDK_ROOT/platforms/android-18/arch-arm/usr/lib/crtbegin_dynamic.o
I use gcc4.8 and android API-level18
usin this you can try:
First way using command line.
export NDK_ROOT=your_ndk_path
export PATH=$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin:$PATH
export CC=arm-linux-androideabi-gcc
export LD=arm-linux-androideabi-ld
export CPPFLAGS=-I$NDK_ROOT/platforms/android-18/arch-arm/usr/include
export CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-18/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-18/arch-arm/usr/lib"
export LIBS="-lc"
arm-linux-androideabi-gcc -nostdlib -o test test.c
If run "file test" you should see this:
test: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
Second way using autotools.
export PATH=$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin:$PATH
./configure --host=arm-linux-androideabi CC=arm-linux-androideabi-gcc LD=arm-linux-androideabi-ld CPPFLAGS="-I$NDK_ROOT/platforms/android-18/arch-arm/usr/include" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-18/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-18/arch-arm/usr/lib" LIBS="-lc"
make
http://embelinux.blogspot.com/2013/09/autotools1-hola-mundo-la-autotools.html
Third way using android developers ndk full feature.
Read Android.mk file syntax specification. This document describes the
syntax of Android.mk build file written to describe your C and C++ source
files to the Android NDK.
http://www.kandroid.org/ndk/docs/ANDROID-MK.html
gdbserver is to debug an application running on the Android device and can
control gdb from the PC using a TCP connection. gdb (The GNU Debugger)
need the debugging symbols.
When you compile an application the compiler puts all the symbols defined
in something called as symbol table, the problem was not link to rtbegin_dynamic.o,
crtend_android.o that if you specify -nostdlib option the program is created but no work (Table Simbol empty)
nm (list symbols from object files) eg: nm test
gcc is not a compiler, it is a driver that controls the execution
of other applications that are what make the job
for example try invoque the compiler using -### as unique option for see details
LDFLAGS: are the flags for the linker
CFLAGS: are the flags to the compiler (not links)
Anyway if you are new to the compilation, even in cross compiling strongly
recommend you use the Android.mk way
Sorry for my English ;)
#Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#module name
LOCAL_MODULE := test
#src
LOCAL_SRC_FILES := test.c
#build executable
include $(BUILD_EXECUTABLE)
export PATH=path_to_ndk_root:$PATH
export NDK_PROJECT_PATH=.
ndk-build APP_BUILD_SCRIPT=Android.mk

Compiling a C program issue in the terminal

I am trying to compile a C program in the terminal.
This is my command:
gcc -1 string -o syncing.c -o syncing
This is my result:
clang: error: no input files
I know that -1... indicates the library I used, syncing.c is the C file I am trying to compile.
What am I doing wrong with my command or is it something else?
I am only using standard libraries.
Please read up on how to use GCC, GCC command-line options and also official command-line documentation. You are telling it that syncing.c is your output file. But you want it to be your input file.
Also, I am not so sure on the -1 there. You might want to have a look at this on how to include/link external libraries. Here are more examples on that.
You probably meant something like:
gcc syncing.c -lstring -o syncing

How compile on linux KNN CUDA?

Recently, I found knn CUDA which is a group of Mex file that implement knn search based on brute force, but in the README.md I have not found the way to compile this files in matlab using a linux distribution. I would appreciate ideas about how cope with this issue.
I'm the author of this kNN code :)
Back in 2008, the code was written using the Windows XP OS.
Since I provide the source code, you should be able to produce linux mex files.
In the ReadMe, I give the following command line for Windows :
nvmex -f nvmexopts.bat knn_cuda_with_indexes.cu -I'C:\CUDA\include' -L'C:\CUDA\lib' -lcufft -lcudart -lcuda -D_CRT_SECURE_NO_DEPRECATE
Adapt it for your Linux distribution to generate your mex file.
A lot of things may have changed in 5 years so you may have to modify a few things.
However, the feedbacks I got from users indicate that it works just fine.
Try also to read about how to compile a CUDA code under Linux.
I guess NVidia provides a pretty nice tutorial.
You can also compile cuda+mex without nvmex. In MATLAB command, simply run the following two lines
>> !nvcc -c yourfile.cu -Xcompiler -fPIC -I$matlabroot/extern/include -I$matlabroot/toolbox/distcomp/gpu/extern/include
>> mex yourfile.o -L/usr/local/cuda/lib64 -L$matlabroot/bin/glnxa64 -lcudart -lcufft -lmwgpu
replace $matlabroot with appropriate path. (Note that ! invoke system command in matlab)
The first line create object file and then mex links library.
You might have to modify your CUDA path to /usr/loca/cuda-6.0/ or /usr/local/cuda-YOUR_VERSION/. Also for the cuda library /usr/local/cuda/lib64 or /usr/local/cuda/lib Please check.
If you want to optimize your code simply put -O3 -DNDEBUG
>> !nvcc -O3 -DNDEBUG -c yourfile.cu -Xcompiler -fPIC -I$matlabroot/extern/include -I$matlabroot/toolbox/distcomp/gpu/extern/include
the library link command is same.
Also please note that additional include path -I$path and library path -L$path or library -l$library might be required to suit your need.

Resources