OpenCL CL/cl.h error on windows 7 with mingw32 - makefile

I am trying to compile my OpenCL app with the following command in mingw32 :
mingw32-gcc -o plat plat.c
but i recieve this error :
CL/cl.h no such file or directory
I searched many times all over the net and this site but can't find any good answer.
I did every work but it still makes error.
I use AMD Radeon HD 5470 and have installed the latest catalyst Driver and AMD APP SDK 2.8 on win 7
I have installed VS 2012
in my code I use several states with hope to work but .... it still makes the same error
I also used -I & -L in compile command and it still makes error : CL/cl.h no such file or directory
how ever I don't know how could use make file to compile the code
I 'll be so thankful any one whom help me : mehdioraki59#yahoo.com
My system is : dell studio 1558
this is my very very simple testing code :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef MAC
#include <OpenCL/cl.h>
#else
#include <C:\Program Files (x86)\AMD APP\include\CL\cl.hpp>
//#include <CL/cl.h> >>>>>>> i manually disabled this line but there is still error
#endif
int main() {
cl_platform_id *platforms;
cl_uint num_platforms;
cl_int i, err, platform_index = -1;
char* ext_data;
size_t ext_size;
err = clGetPlatformIDs(1, NULL, &num_platforms);
if(err < 0) {
perror("Couldn't find any platforms.");
exit(1);
}
free(platforms);
return 0;
}

You need to add -I"C:\Program Files (x86)\AMD APP\include" to your build command to tell mingw32-gcc where to find CL/cl.h. Using this, the line #include should work properly.

I finally found the answer also thank you mr chippies :
how ever your advise helped me more
i used this make file :
PROJ=qwerty_mehdi
CC=mingw32-gcc
CFLAGS=-Wall
LIB=-lOpenCL
ifdef AMDAPPSDKROOT
INC_DIRS="$(AMDAPPSDKROOT)include"
LIB_DIRS="$(AMDAPPSDKROOT)lib\x86"
else
ifdef NVSDKCOMPUTE_ROOT
INC_DIRS="$(NVSDKCOMPUTE_ROOT)\OpenCL\common\inc"
LIB_DIRS="$(NVSDKCOMPUTE_ROOT)\OpenCL\common\lib\Win32"
endif
endif
$(PROJ): qwerty.c
$(CC) $(CFLAGS) -o $# $^ -I$(INC_DIRS) -L$(LIB_DIRS) $(LIB)
and also deleted this line :
#include
and after this the .exe was made successfully
in the lines of make file code the qwerty.c is the codes i explained before .

Related

Makefile error, make *** no targets specified and no makefile found. stop

i am very new in build systems and i am trying to build c++ file with mingw compiler and makefile on windows.
i installed mingw and added it to PATH. My code as follows
//main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World !!!! "
return 0;
}
//Makefile
program:
g++ main.cpp -o program
i change my working directory as C:\MyDir which is included my .cpp and Makefile
cd C:\\MyDir
C:\\MyDir> make
i get the error
make *** no targets specified and no makefile found. stop ...
Do you have any idea about this problem, thanks..

Linking error in C++

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.

mingw C++ won't compile j0 funciton

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

Problem understanding the make utility and the header .h files usage

I am trying to learn the make command but I am having a little trouble with the way headers are being used
I got prg1.c
#include <stdio.h>
main()
{
printf("Hello World\n");
print();
}
and the prg2.c
#include <stdio.h>
print()
{
printf("Hello World from prg2\n");
}
and here is the make file
objects = prg1.o prg2.o
exe : $(objects)
cc -o exe $(objects)
prg1.o : prg1.c
cc -c prg1.c
prg2.o : prg2.c
cc -c prg2.c
This works perfectly. But if I don't include stdio.h in both file and then I have to compile it using the make, how am I supposed to write the makefile?
If you don't include <stdio.h>, then you can do one of two things:
supply a correct declaration for printf yourself:
int printf(const char *fmt, ...);
There is almost never any reason to do such a thing.
If your compiler is GCC, use the -include compiler option to force the inclusion of "stdio.h":
prg1.o: prg1.c
gcc -c -include stdio.h prg1.c
This is completely hokey; don't do it.
Note that the make utility has nothing to do with ensuring that the correct header material is included in C translation units. make is a utility which runs shell commands in response to some files not existing or having modification stamps older than other files.

Linking gnu libraries c++ and fortran

I have spent the day searching for an answer to what should be a simple problem. I am building a c++ program to call a fairly large amount of existing fortran. I started by changing the fortran main to a subroutine and then called it with a simple c++ main. My steps look like:
gfortran -c f1.f90 f2.f90 ......
g++ -c mn.cpp
gfortran -lstdc++ -o prog.exe mn.o f1.o ....
mn.cpp started out looking like the code below, and the above steps do work ok. I get a host of linker errors if I try to link with:
g++ -lgfortran (this never works!)
Next, I tried to instantiate a simple array class (remove the 2 commented lines). This produced linker errors concerning gxx_personality_seh0, vtable, and operator new.I get similar errors if I just create an array of doubles with new (remove comment), and if I remove the call to the fortran program completely (still linking with gfortran). Obviously, -lstdc++ does not bring in all the libraries needed. Which libraries are needed and how can I get it to link them?
I am using Windows 7 with Cygwin. The libraries it links are in ...lib/x86_64-pc-cygwin/4.9.3. I can post the linker output if it would be helpful.
mn.cpp which works (code commented out) is below:
#include <string.h>
#include <stdlib.h>
//#include "array.h"
extern "C" {
void mnf90_(const char*,int);
}
int main(int argc, char* argv[]){
// Array2D A; // first derivative
static const char *feos = "d/fld9x.dat";
int npoint = 20;
// double *xc = new double[npoint];
mnf90_(feos,strlen(feos));
}

Resources