Ошибки сборки: LNK2019 & LNK1120 в проекте консольного приложения QtVS 2015 - PullRequest
0 голосов
/ 08 октября 2019

** У меня есть C ++ API и соответствующий файл библиотеки (api-140.lib), с помощью которого я разрабатываю проект с графическим интерфейсом в Microsoft Visual Studio-2015 с помощью Qt. Прежде всего я проверяю код в консольном приложении.

Перед сборкой проекта я выполнил следующие действия:

* Введен IP-адрес в аргументе командной строки. ,

Добавлен путь к файлу библиотеки в Свойства-> Компоновщик-> Дополнительные каталоги библиотек &

Добавлен файл библиотеки в Свойства-> Компоновщик-> Ввод-> Дополнительные зависимости *

Во время сборки проекта я структурирую с ошибками компоновщика. Я новичок в Qt & MSVS. Пожалуйста, помогите мне исправить эту ошибку. [Введите описание изображения здесь] [1]

Ниже приведены сведения о моей системе: Windows 10 64 бит VS-2015, Qt-5.6.0 (qt-opensource-windows-x86-msvc2015_64-5.6.0) **

Мой код C ++: main.cpp

#include <string>
#include <stdint.h>
#include <stdio.h>
#include <tchar.h>
#include <winsock2.h>
#include <QtCore/QCoreApplication>
#include "qtcpserver.h"


#pragma comment (lib, "Ws2_32.lib")


#ifdef _UNICODE
std::string convertToString(_TCHAR* textW)
{
    std::string result;

    int lenA = WideCharToMultiByte(CP_ACP, 0, textW, -1, 0, 0, NULL, NULL);
    printf("lenA = %d\n", lenA);
    if (lenA > 0)
    {
        char* textA = new char[lenA + 1]; // allocate a final null terminator as well
        printf("textA = %p\n", textA);
        WideCharToMultiByte(CP_ACP, 0, textW, -1, textA, lenA, NULL, NULL);
        printf("%d\n", __LINE__);
        textA[lenA] = 0; // Set the null terminator yourself
        result = textA;
        delete[] textA;
    }

    return result;
}
#endif



#define GE_COMMON_VERSION "2.4.1"
#define GE_OK 0
#define GE_ERROR 1
#define GE_OVERFLOW 2
#define GE_INVALID_PARAMETER 3
#define GE_RESOURCE_UNAVAILABLE 4
#define GE_FILE_IN_USE 5
#define GE_ADDRESS_EXISTS 6
#define GE_INVALID_ADDRESS 7
#define GE_NOT_EXISTING 8
#define GE_UNDERRUN 9
#define GE_ABORT 10
#define GE_COMMFAIL 11
#define GE_BUSY 12
#define GE_NO_ACCESS 13
#define GE_NOT_PERMITTED 14
#define GEC_SFPDP_RECORDER_VERSION "3.5.0"

#define GEC_SFPDP_RECORDER_SERVER_UNIX_SOCKET_FILE "/tmp/ge-sfpdp-server"
#define GEC_SFPDP_RECORDER_SERVER_TCP_PORT 8001

#define GEC_SFPDP_NO_WAIT_FOR_SYNC  0
#define GEC_SFPDP_WAIT_FOR_ANY_SYNC  1

#define GEC_SFPDP_PLAYBACK_WITHOUT_SIGNALS       0
#define GEC_SFPDP_PLAYBACK_WITH_UNTIMED_SIGNALS  1
#define GEC_SFPDP_PLAYBACK_WITH_TIMED_SIGNALS    2

#define GEC_SFPDP_512_WORDS_CYCLE  0
#define GEC_SFPDP_16K_WORDS_CYCLE  1
#define GEC_SFPDP_512K_WORDS_CYCLE 2
#define GEC_SFPDP_16M_WORDS_CYCLE  3

#define GEC_SFPDP_INTERNAL_CHANNEL_SYNC_MASTER_0  (1 << 0)
#define GEC_SFPDP_INTERNAL_CHANNEL_SYNC_MASTER_1  (1 << 1)
#define GEC_SFPDP_INTERNAL_CHANNEL_SYNC_MASTER_2  (1 << 2)
#define GEC_SFPDP_INTERNAL_CHANNEL_SYNC_MASTER_3  (1 << 3)
#define GEC_SFPDP_EXTERNAL_CHANNEL_SYNC_EXT0      (1 << 4)
#define GEC_SFPDP_EXTERNAL_CHANNEL_SYNC_EXT1      (1 << 5)
#define GEC_SFPDP_EXTERNAL_CHANNEL_SYNC_EXT2      (1 << 6)
#define GEC_SFPDP_EXTERNAL_CHANNEL_SYNC_EXT3      (1 << 7)

#define GEC_SFPDP_AUTOMATIC_CONTROL  0
#define GEC_SFPDP_MANUAL_CONTROL     1

#define GEC_SFPDP_START_CHANNEL_SYNC  0
#define GEC_SFPDP_PAUSE_CHANNEL_SYNC  1
#define GEC_SFPDP_STOP_CHANNEL_SYNC   2

enum {
    GEC_SFPDP_1_0625_GBPS,
    GEC_SFPDP_2_125_GBPS,
    GEC_SFPDP_2_5_GBPS,
    GEC_SFPDP_3_125_GBPS,
    GEC_SFPDP_4_25_GBPS
};




class GEC_ISfpdpRecorder
{
public:
    virtual int setIntChannelSyncControl(int mode) = 0;
    virtual int setIntChannelSync(uint32_t iDevice, int masterMask, int action) = 0;
    virtual int setChannelSyncOutput(uint32_t iDevice, int signal, int source) = 0;
    virtual int reset() = 0;
    virtual int create(std::string path, std::string name, uint32_t iDevice, uint32_t iPort, uint32_t& id) = 0;
    virtual int open(std::string path, std::string name, uint32_t iDevice, uint32_t iPort, int mode, uint32_t& id) = 0;
    virtual int destroy(uint32_t id) = 0;
    virtual int setCRC(uint32_t id, bool enableCRC) = 0;
    virtual int setCopyMode(uint32_t id, bool enable) = 0;
    virtual int setWaitForSync(uint32_t id, int mode) = 0;
    virtual int setMaxSize(uint32_t id, uint64_t sizeInBytes) = 0;
    virtual int setLinkSpeed(uint32_t id, int speed) = 0;
    virtual int setFlowControl(uint32_t id, bool enable) = 0;
    virtual int setRateControl(uint32_t id, int cycleSize, uint32_t cyclePartsForTx) = 0;
    virtual int setSimplexLinkMode(uint32_t id, bool enable) = 0;
    virtual int setChannelSyncSource(uint32_t id, int source) = 0;
    virtual int setSwapping(uint32_t id, bool enable8in16, bool enable16in32) = 0;
    virtual int getStatus(uint32_t id, uint64_t& numBytes, std::string& state) = 0;
    virtual int checkForOverflow(uint32_t id, bool& detected, bool clear) = 0;
    virtual int startAll() = 0;
    virtual int stopAll() = 0;
};


class GEC_SfpdpRecorderFactory
{
public:
    static GEC_ISfpdpRecorder* createTcpBasedInstance(std::string address);
    static void destroyTcpBasedInstance(GEC_ISfpdpRecorder* instance);
};



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

    if (argc < 2) {
        printf("ERROR: Missing argument with the IP address of the SFPDP Record Manager Server\n");
        return -1;
    }

    // Initialize Winsock
    WSADATA wsaData;
    int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (result != 0) {
        printf("WSAStartup failed with error: %d\n", result);
        return -1;
    }

    int status = 0;
    std::string ipAddress;
    #ifdef  _UNICODE
    ipAddress = convertToString(argv[1]);
#else
    ipAddress = argv[1];
#endif
    GEC_ISfpdpRecorder* instance = GEC_SfpdpRecorderFactory::createTcpBasedInstance("ipAddress");
    if (instance) {
        int status = instance->reset();
        printf("reset() returned %d as return code\n", status);

        uint32_t id = 0;
        status = instance->create("/data", "test", 0, 0, id);
        printf("create() returned %d as return code\n", status);
        printf("         and 0x%x as id\n", id);

        status = instance->startAll();
        printf("startAll() returned %d as return code\n", status);

        uint64_t numBytesRecorded = 0;
        std::string state;
        status = instance->getStatus(id, numBytesRecorded, state);
        printf("getStatus() returned %d as return code,\n", status);
        printf("            %lld as number of recorded bytes,\n", numBytesRecorded);
        printf("            and %s as state\n", state.c_str());

        for (int i = 0; i < 12; ++i) {
            Sleep(5000);

            status = instance->getStatus(id, numBytesRecorded, state);
            printf("getStatus() returned %d as return code,\n", status);
            printf("            %lld as number of recorded bytes,\n", numBytesRecorded);
            printf("            and %s as state\n", state.c_str());
        }


        status = instance->stopAll();
        printf("stopAll() returned %d as return code\n", status);

        status = instance->destroy(id);
        printf("destroy() returned %d as return code\n", status);

        GEC_SfpdpRecorderFactory::destroyTcpBasedInstance(instance);
    }
    WSACleanup();

    return a.exec(),status;

}


Build Process:

1>------ Build started: Project: sfpdpgui1, Configuration: Debug x64 ------
1>  Moc'ing sfpdpgui1.h...
1>  moc_sfpdpgui1.cpp
1>  main.cpp
1>  sfpdpgui1.cpp
1>  Generating Code...
1>main.obj : error LNK2019: unresolved external symbol "public: static class GEC_ISfpdpRecorder * __cdecl GEC_SfpdpRecorderFactory::createTcpBasedInstance(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?createTcpBasedInstance@GEC_SfpdpRecorderFactory@@SAPEAVGEC_ISfpdpRecorder@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: static void __cdecl GEC_SfpdpRecorderFactory::destroyTcpBasedInstance(class GEC_ISfpdpRecorder *)" (?destroyTcpBasedInstance@GEC_SfpdpRecorderFactory@@SAXPEAVGEC_ISfpdpRecorder@@@Z) referenced in function main
1>C:\Users\Vignesh\Documents\Visual Studio 2015\Projects\sfpdpgui1\x64\Debug\\sfpdpgui1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Build Errors:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "public: static class GEC_ISfpdpRecorder * __cdecl GEC_SfpdpRecorderFactory::createTcpBasedInstance(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?createTcpBasedInstance@GEC_SfpdpRecorderFactory@@SAPEAVGEC_ISfpdpRecorder@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function main sfpdpgui1   C:\Users\Vignesh\Documents\Visual Studio 2015\Projects\sfpdpgui1\sfpdpgui1\main.obj 1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl GEC_SfpdpRecorderFactory::destroyTcpBasedInstance(class GEC_ISfpdpRecorder *)" (?destroyTcpBasedInstance@GEC_SfpdpRecorderFactory@@SAXPEAVGEC_ISfpdpRecorder@@@Z) referenced in function main   sfpdpgui1   C:\Users\Vignesh\Documents\Visual Studio 2015\Projects\sfpdpgui1\sfpdpgui1\main.obj 1   
Error   LNK1120 2 unresolved externals  sfpdpgui1   C:\Users\Vignesh\Documents\Visual Studio 2015\Projects\sfpdpgui1\x64\Debug\\sfpdpgui1.exe   1   

**Please find the link for Error image:**

  [1]: https://i.stack.imgur.com/p2MY8.png
...