如何在vs代码C ++中添加静态库?

问题描述

我一直在寻找很多天,我试图在vs代码中使用c ++,但是我无法链接库。我曾尝试使用GCC和MSVC编译器,但我是一个初学者,不知道该走哪条路。您能帮我将库与MSVC编译器链接吗? MSVC错误"LINK : Fatal error LNK1561: entry points must be set",with GCC I get something like that.

MSVC脚本.bat:

@echo off
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" (
    call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86
) else (
    if exist "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" (
        call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
    ) else (
        call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86
    )
)
set compilerflags=/Od /Zi /EHsc /std:c++latest /I include
set linkerflags=/OUT:bin\main.exe
cl.exe %compilerflags% src\*.cpp /link %linkerflags%
del bin\*.ilk *.obj *.pdb

脚本C ++:

#include <iostream>
#include "../include/SDL.h"

int main(int argc,char *argv[])
{
    SDL_Window *window;

    SDL_Init(SDL_INIT_VIDEO);

    window = SDL_CreateWindow(
        "An SDL2 window",SDL_WINDOWPOS_UNDEFINED,640,480,SDL_WINDOW_OPENGL);

    if (window == NULL)
    {
        std::cout << "error in create window" << std::endl;
        return 1;
    }

    SDL_Delay(3000);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)