0

I get the error LNK2001 when I try to compile the following code, although I have configured the compiler's additional include directory, and the linker's additional library directory.

#include "stdafx.h"
#include <QCamApi.h>

int _tmain(int argc, _TCHAR* argv[])
{


    QCam_Err            errcode = qerrSuccess ; 
    errcode = QCam_LoadDriver();


    if(errcode == qerrSuccess){QCam_ReleaseDriver();}

    return 0;
}

I also have an example that does work with the same compiler/linker settings

#include <stdio.h>
#include <stdlib.h>
#include <QCamApi.h>

//===== Main ==============================================================
int main(int argc, char* argv[])
{


    QCam_Err            errcode = qerrSuccess ;

    errcode = QCam_LoadDriver();

    if(errcode == qerrSuccess) {QCam_ReleaseDriver();}

    return 0;
}

yet somehow I can't seem to be able to start this from scratch. Why does it not work if I start an empty project and just paste this code in the .cpp? Sorry if that's a trivial question, and many thanks for your time!

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Aline
  • 9
  • 1
  • 2

2 Answers2

0

Your separate use of main in the working example but _tmain in the other seems to imply that your projects are set up different - specifically I suspect that one project is set to Multi-byte characters and the other to unicode.

I think that this is causing your linking issues.

Here is a more complete discussion.

Community
  • 1
  • 1
Elemental
  • 7,365
  • 2
  • 28
  • 33
0

To link external function written in C from C++, they should be declared as extern "C".

You should add in each declaration to the called functions of QCamApi.h the extern "C" keyword, or try to compile your code in plain C and not C++.

Zac
  • 4,510
  • 3
  • 36
  • 44