I have been trying all day to get this working and everything that I find on the internet to try fails.
Using Geany on the Raspbery Pi I want to make a GUI for C.
In my build commands I have this
gcc `pkg-config --cflags gtk+-3.0` -Wall -o "%e" "%f" `pkg-config --libs gtk+-3.0`
And here is my code. I commented out the parts for wiringpi for now.
//#include <wiringPi.h>
#include <gtk/gtk.h>
int main(int argc, char **argv)
{
gtk_init (&argc, &argv);
//wiringPiSetup () ;
//pinMode (0, OUTPUT) ;
while (1){
//digitalWrite (0, HIGH) ;
//delayMicroseconds(30);
//digitalWrite (0, LOW) ;
//delayMicroseconds(30);
}
return 0;
}
I get the following errors
Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing gtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0' found
Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containinggtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0' found
untitled.c:2:21: fatal error: gtk/gtk.h: No such file or directory
It looks like I might be missing a gtk+-3.0.pc file. If that is the case where might I look for it, and if I don't have it then where do I get it?
Related
The question here gives an example of how to use xgboost - a machine learning library written in C++. I want to run the example, and therefore install the library for C++. I added the /lib files to /usr/local/lib and /src files to /usr/local/src
I am able to compile this much part of the example :
#include <iostream>
#include <xgboost/c_api.h>
using namespace std;
int main(){
int cols=3,rows=5;
float train[rows][cols];
for (int i=0;i<rows;i++)
for (int j=0;j<cols;j++)
train[i][j] = (i+1) * (j+1);
float train_labels[rows];
for (int i=0;i<rows;i++)
train_labels[i] = 1+i*i*i;
DMatrixHandle h_train[1];
XGDMatrixCreateFromMat((float *) train, rows, cols, -1, &h_train[0]);
}
However, I am getting a linking error:
/tmp/ccuBacNh.o: In function `main':
TerrainPredict.cpp:(.text+0x278): undefined reference to `XGDMatrixCreateFromMat'
collect2: error: ld returned 1 exit status
How can I resolve this. I concluded that cpp files are missing, but I don't know where to put them. I want help regarding how to proceed with installation.
I also tried using a makefile:
LDLIBSOPTIONS=xgboost/lib/libxgboost.a xgboost/rabit/lib/librabit.a xgboost/dmlc-core/libdmlc.a -lpthread
CFLAGS=-I xgboost/include -I xgboost/rabit/include -I dmlc-core/include
all:
g++ main.cpp $(CFLAGS) $(LDLIBSOPTIONS)
I put Makefile, main.cpp and xgboost directory in the same folder.
In that case I am getting a longer linking error. Error is too long to include fully. Here it is.
I am trying to compile a source given a .so file libfoo.so. The only thing in this library is a function that just returns a number (yeah, I know, advanced stuff). The header file equivalent (I was provided with both, but am only supposed to use the .so) is named foo.h and the function is named int foo().
My source file is main.c:
#include <stdio.h>
#include "foo.h"
int main()
{
int x = foo();
printf("%d", x);
return 0;
}
Now, when trying to compile I have the following commands:
gcc -Wall -fPIC -c main.c -o main.o
gcc -Wall -fPIC main.o -o main -lfoo -L.
The first command fails to create the object file, outputting the following error:
fatal error: foo.h: No such file or directory
I am using Ubuntu 16.04.
I have also tried exporting the current location to LD_LIBRARY_PATH as I've seen suggested on a few other answers.
export LD_LBIRARY_PATH=$LD_LIBRARY_PATH:machine/Desktop/lib_test
You need to have the interface definition from the .h file and that file must be in the current directory or a directory on the include search path.
Note that on some systems filenames and paths are case dependent.
I'm trying to compile a program on Windows using MingW (msys2) and it fails with the j0 function. On Linux it compiles no problem. It seems to hate when I use the -std=c++11 flag on the compiler. How can I get this to compile properly and with the -std=c++11 flag on?
Sample code:
#include <cmath>
int main( int argc, char *argv[] )
{
float test = j0( 5 );
}
Output
$ g++ -std=c++11 test.cpp -o test
test.cpp: In function 'int main(int, char**)':
test.cpp:6:21: error: 'j0' was not declared in this scope
float test = j0( 5 );
Apparently, MinGW defines the Bessel functions only when __STRICT_ANSI__ is not defined, and it is defined when -std=c++11 is specified. I was able to get your code to compile in MinGW by adding #undef __STRICT_ANSI__ at the top of the file. See https://sourceforge.net/p/mingw-w64/feature-requests/68/
You might also try -std=gnu++11 instead. See https://stackoverflow.com/a/19667112/10077
I've been trying to link to the functions in the cutil.h ofthe GPU Computing SDK released by NVIDIA.
At the moment, I am simply trying to compile this simple piece of code:
#include <iostream>
#include <cuda.h>
#include <cutil.h>
using namespace std;
int main(){
unsigned int time_total;
cutCreateTimer(&time_total);
return 0;
}
using the following command:
nvcc -I/home/sj755/NVIDIA_GPU_Computing_SDK/C/common/inc/ -L/home/sj755/NVIDIA_GPU_Computing_SDK/C/lib/libcutil_x86_64.a cutiltest.cu
Only to get the following error:
/tmp/tmpxft_000077cc_00000000-13_cutiltest.o: In function `main':
tmpxft_000077cc_00000000-1_cutiltest.cudafe1.cpp:(.text+0x10): undefined reference to
`cutCreateTimer'
collect2: ld returned 1 exit status
ld also can't find -lcutil if I were to add the flag.
There is a static library that I'm supposed to link to, but for some reason this never works out. Here's what I tried:
I've changed my .bashrc file so that LD_LIBRARY_PATH includes the path to the static library
##########< CULA >
export CULA_ROOT=/usr/local/cula
export CULA_INC_PATH=$CULA_ROOT/include
export CULA_BIN_PATH_32=$CULA_ROOT/bin
export CULA_BIN_PATH_64=$CULA_ROOT/bin64
export CULA_LIB_PATH_32=$CULA_ROOT/lib
export CULA_LIB_PATH_64=$CULA_ROOT/lib64
##########< CUDA >
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=:/usr/local/cuda/lib64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CULA_LIB_PATH_64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/libnvvp/
export CUDA_SDK_ROOT_DIR=/home/sj755/NVIDIA_GPU_Computing_SDK/C
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_SDK_ROOT_DIR/lib
I've also tried renaming libcutil_x86_64.a to libcutil.a, still nothing.
Tried extracting the archive, creating a shared object file, and linking to it:
ar -x libcutil_x86_64.a
gcc -I /usr/include/GL/ -L /usr/include/GL/ -lglut -lGL -lGLU -lX11 -lXmu -lXi -lm -lpthread -shared *.cpp.o -o libcutil.so
nvcc -lcutil -I /home/sj755/NVIDIA_GPU_Computing_SDK/C/common/inc/ -L /home/sj755/NVIDIA_GPU_Computing_SDK/C/lib/libcutil.so cutiltest.cu
Only to get the following /usr/bin/ld: cannot find -lcutil
What step am I forgetting here?
Your compilation statement is incorrect. It should look something like this:
nvcc -I$SDKROOT/C/common/inc -L$SDKROOT/C/lib cutiltest.cc -lcutil_x86_64
where SDKROOT holds the root path to the SDK, which looks to be
/home/sj755/NVIDIA_GPU_Computing_SDK
in your case. The key things to note here are that the library must be passed by name as a -l option after the code and objects that require it. A concrete example on OS X using your code snippet:
$ cat cutiltest.cc
#include <iostream>
#include <cuda.h>
#include <cutil.h>
using namespace std;
int main(){
unsigned int time_total;
cutCreateTimer(&time_total);
return 0;
}
$ nvcc -I/Developer/GPU\ Computing/C/common/inc -L /Developer/GPU\ Computing/C/lib -o cutiltest cutiltest.cc -lcutil_i386
$ ls -l cutiltest
-rwxr-xr-x 1 talonmies talonmies 117548 May 25 07:57 cutiltest
But as a last remark, you really should rethink your choice of using the SDK cutils library at all. It is only intended for use with the SDK examples. It isn't part of CUDA, it has no documentation, it isn't guaranteed to work or not contain bugs, and isn't guaranteed to be consistent (or even present) from one SDK release to another.
This is not only your problem. Are you tried to link with cutil as with shared library? This solution was posted on NVIDIA dev. zone forum
I am trying to run a simple program in cygwin that includes fork and wait.
I thought it would be very easy to compile but I am having problems.
#include <stdio.h>
#include <unistd.h>
void testFork(){}
int main(int argc,char* argv[]){
if (fork()==0) {testFork();return 0;}
while (wait() == -1);
return 0;
}
Compiled using:
gcc -Wall -Wextra -o test.o test
I get the following error:
C:\Users\Aaron\AppData\Local\Temp\ccgh3MfS.o:ostest.c:(.text+0x11): undefined reference to `fork'
C:\Users\Aaron\AppData\Local\Temp\ccgh3MfS.o:ostest.c:(.text+0x22): undefined reference to `wait'
collect2: ld returned 1 exit status
I'm sure I'm missing something trivial. Any ideas?
The linker can't find the standard C libraries.
Did you install Cygwin in the normal way? (Here's a simple guide: http://www.eecg.utoronto.ca/~aamodt/ece242/cygwin.html).
Have you been able to compile even simpler programs:
#include <stdio.h>
int main(int argc, char **argv) {
printf("Found C library.\n");
}
If that doesn't compile, you might just want to try removing and reinstalling Cygwin - something is broken.
C:\Users\Aaron\AppData\Local\Temp\ccgh3MfS.o is a Windows-style path. If you're using Cygwin, you only be seeing Cygwin-style paths, perhaps something like /cygdrive/C/Users/Aaron/AppData/Local/Temp/ccgh3MfS.o.
You said your command line was
gcc -Wall -Wextra -o test.o test
but it was probably
gcc -Wall -Wextra -o test.o test.c
Are you invoking gcc from the Cygwin command line? What does type gcc say?
It seems that MinGW gcc is being invoked because the cygwin gcc package is not installed.
You can verify that by calling the "cygcheck -c" in the cygwin commandline which will list all the installed packages, if you can't find the gcc in the list you need to install it