{"id":6133,"date":"2014-04-13T04:33:36","date_gmt":"2014-04-13T04:33:36","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/cundefined-reference-while-compiling-opencl-program-collection-of-common-programming-errors\/"},"modified":"2014-04-13T04:33:36","modified_gmt":"2014-04-13T04:33:36","slug":"cundefined-reference-while-compiling-opencl-program-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/cundefined-reference-while-compiling-opencl-program-collection-of-common-programming-errors\/","title":{"rendered":"[C]undefined reference while compiling openCL program-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to compile something to try out openCl, but i&#8217;m having a few problems..<\/p>\n<p>Here the code<\/p>\n<p>prova.c<\/p>\n<pre><code>#include \n#include \n#include \"Utils\\util.h\"\n#include \n\nint main(){\n    cl_int error = 0;   \/\/ Used to handle error codes\n    cl_int max_platforms = 1; \/\/ The maximum number of platforms\n    cl_uint adviable_platforms = 0; \/\/The adviable number of platforms\n    cl_platform_id* platform;\n\n    error = clGetPlatformIDs(0, NULL, &amp;adviable_platforms);\n    if(adviable_platforms == 0)\n    {\n        printf(\"No adviable platforms.\\n\");\n        return -1;\n    } else {\n        platform = (cl_platform_id*)malloc(adviable_platforms * sizeof(cl_platform_id));\n    }\n\n    error = clGetPlatformIDs(adviable_platforms, platform, NULL);\n\n\n    printf(\"clGetPlatformIDs: %s\\n\", clErrorString(error));\n    return 0;\n}\n<\/code><\/pre>\n<p>I&#8217;m compiling on win 7 64 with mingw32. The opencl headers are in the include directory of mingw while utils.h(inside the directory Utils inside the directory of prova.c) defines clErrorString(that simply convert the error into a more human readable string).<\/p>\n<p>To compile i use<\/p>\n<pre><code>gcc -L\\Utils prova.c\n<\/code><\/pre>\n<p>But i always get<\/p>\n<pre><code>C:\\[stuff]\\ccEjYQbj.o:prova.c:(.text+0x42): undefined reference to 'clGetPlatformIDs@12'\nC:\\[stuff]\\ccEjYQbj.o:prova.c:(.text+0x8d): undefined reference to 'clGetPlatformIDs@12'\nC:\\[stuff]\\ccEjYQbj.o:prova.c:(.text+0x9e): undefined reference to 'clErrorString'\n<\/code><\/pre>\n<p>I&#8217;m not so good with compilers, so i image i&#8217;m missing something, but i really don&#8217;t know what..<\/p>\n<p>EDIT: Sincerely, i tried every command come to my mind. using -L to include directories, -l to link to files, using ar..<\/p>\n<p>This is the last &#8220;script&#8221; i tried<\/p>\n<pre><code>set PATH=%PATH%;C:\\Python26;C:\\MinGW\\bin;C:\\MinGW\\lib\n\ncd Utils\ngcc -c util.c -l\"C:\\Program Files (x86)\\AMD APP\\lib\\x86_64\\libOpenCL.a\" -o util.o\nar rcs libutil.a util.o\n\ncd..\npause\n\ngcc -c prova.c -l\"Utils\\libutil.a\" -o prova.exe\n\npause\n<\/code><\/pre>\n<p>EDIT2:<\/p>\n<pre><code>@echo off\nset PATH=%PATH%;C:\\Python26;C:\\MinGW\\bin;C:\\MinGW\\lib\n\ncd Utils\ngcc -Wall -c util.c -L\"C:\\Program Files (x86)\\AMD APP\\lib\\x86_64\\\" -o util.o\nar rcs libutil.a util.o\n\ncd..\npause\n\ngcc -Wall -c prova.c -L\"C:\\Program Files (x86)\\AMD APP\\lib\\x86_64\\\" -l\"Utils\\libutil.a\" -o prova.exe\n\npause\n<\/code><\/pre>\n<p>No errors, the only warning is max_platform is unused. Then i find util.o and libutil.a(size 5kb) in Utils and prova.o(size 1kb). If i try to run prova.o, it says that the file version is not compatible with the current windows version, check the system version (x86 or x64) and contact the software distributor<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to compile something to try out openCl, but i&#8217;m having a few problems.. Here the code prova.c #include #include #include &#8220;Utils\\util.h&#8221; #include int main(){ cl_int error = 0; \/\/ Used to handle error codes cl_int max_platforms = 1; \/\/ The maximum number of platforms cl_uint adviable_platforms = 0; \/\/The adviable number of platforms [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6133","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6133"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6133\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}