简体   繁体   中英

Visual Studio 2012, C/C++ code, error LNK2001: unresolved external symbol

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!

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.

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++.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM