简体   繁体   中英

MFC C++ static library linked with non MFC console app

I'm trying to compile a console program that uses a static library implementing CString.The console app has been created with the VS wizard with : Win32 console application with precompiled headers, SDL verification but without ATL or MFC. The static library is a MFC static library (wizard construction).

Where is (are) my mistake(s) ?

This is what I so long have tried:

I've created a new console app using MFC controls - this compile fine with the static library.

Then I've controlled and modified when necessary every link options, comparing the 2 console projects. But the 1st console application does not compile. I'm stucked ! I'm working with Visual Studio 2012 on Windows 10.

Here is the code : File TestLib.h

#pragma once
#include <atlstr.h>

class TestLib
{
public:
    TestLib(){};
    TestLib(const CString &tst);
    virtual ~TestLib(void);
private:
    CString _tst;
};

Fichier TestLib.cpp

#include "stdafx.h"
#include "TestLib.h"

TestLib::TestLib(const CString &tst)
    : _tst(tst)
{
}

TestLib::~TestLib(void)
{
}

Fichier ConsoleTest2.cpp

// ConsoleTest2.cpp : définit le point d'entrée pour l'application console.
#include "stdafx.h"
#include "TestLib.h"

int _tmain(int argc, _TCHAR* argv[])
{
    TestLib *tst = new TestLib(); // This compile fine !
    //TestLib *tst = new TestLib(_T("Test")); // This generates LNK2019 link error
    return 0;
}

Here is the solution, thanks to Jochen Arndt

Just have to change the TestLib declaration to

TestLib::TestLib(LPCTSTR str)
    : _tst(str)
{
}

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