0

Relearning C++ for the sake of using OpenCL. I have created a Helper Class called CheckDevice which has a bunch of boiler plate code for getting device stats.

CheckDevice.h

    class Utils
    {
    public:
        Utils(){};
        ~Utils(){};


        template<class T>
        static bool IsNull(T Object, char* name);

    private:

    };

CheckDevice.cpp

    cl_command_queue Utils::CreateCommandQueue(cl_context context, cl_device_id *device)
    {
        cl_int err;
        cl_device_id *devices;
        cl_command_queue queue  = NULL;
        size_t deviceBufferSize = -1;
        cl_kernel kernel = 0;


        Utils::IsNull<cl_command_queue>(queue, "Utils::CreateCommandQueue::queue");



        return queue;
    }

main.cpp

    void main()
    {

        cl_kernel kernel            = 0;


        Utils::IsNull<cl_kernel>(kernel, "clCreateKernel");

    }

The question is when calling the function Utils::IsNull from within CheckDevice.cpp it works fine but when calling from main.cpp than I get the following in Visual Studios 2012

error LNK2019: unresolved external symbol "public: static bool __cdecl Utils::IsNull(struct _cl_kernel *,char *)" (??$IsNull@PAU_cl_kernel@@@Utils@@SA_NPAU_cl_kernel@@PAD@Z) referenced in function _main 1>C:\Users\Suri\Documents\Visual Studio 2012\Projects\HelloWorld\Debug\HelloWorld.exe : fatal error LNK1120: 1 unresolved externals

Any Help would be apperciated

billz
  • 44,644
  • 9
  • 83
  • 100
Suri Mtui
  • 13
  • 4
  • `void main()` should be `int main()`. Whatever book or tutorial you're using should not have told you that `void main()` is correct, and your compiler should have warned you about it. Get a better book, and enable warnings in your compiler. – Keith Thompson Sep 07 '13 at 02:35

2 Answers2

1

You don't show the implementation of the IsNull template, but probably it is in CheckDevice.cpp. It should be placed in CheckDevice.h instead, the compiler needs to see it's definition to be able to instantiate it.

sth
  • 222,467
  • 53
  • 283
  • 367
  • Thanks So much it worked. Your right I left the implementation of IsNull out of the question by accident. Why is this the case? I have other functions that have no issue begin called from CheckDevice.cpp. Has it something to do with the template? – Suri Mtui Sep 07 '13 at 02:45
-2
  • There is a calling convention problem on the main.cpp. When you are trying to make a function call on the main, you need first to create an instance of that class object, before you make a function call. You are missing that on your main.
  • So basically you need to create an instance of Utils and make a reference to it.
  • cl_kernel kernel = 0;
  • Utils *ut = new Utils();
  • ut->IsNull"<"cl_kernel">"(kernel, "clCreateKernel");
Juniar
  • 1,269
  • 1
  • 15
  • 24