1

I've been looking for many days I try to work with c++ in the vs code, but I can't link libraries. I've tried using the GCC and MSVC compilers, but I'm a beginner and don't know which way to go. Could you help me link a library with the MSVC compiler?` MSVC error: "LINK : fatal error LNK1561: entry points must be set", with GCC I get something like that.

MSVC script .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

Script 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,
        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;
}

Ruan Lucas
  • 11
  • 2
  • You need to link with SDL2 and SDL2main. Add paths to your `.lib` files to `linkerflags`. – keltar Aug 26 '20 at 12:10
  • Tried do so but it didn't work: ```set linkerflags=/LIBPATH:lib /OUT:binmain.exe``` – Ruan Lucas Aug 26 '20 at 16:16
  • I still don't see any mention of `SDL2` and/or `SDL2main` in your linker flags. If you sure your relative path is correct - add `SDL2.lib SDL2main.lib`; if not - use absolute path. – keltar Aug 27 '20 at 04:15
  • tried ```set linkerflags=/LIBPATH:libSDL2.lib SDL2main.lib /OUT:binmain.exe ``` but I received the error ```LINK : fatal error LNK1181: Could not open the input file 'SDL2main.lib'``` – Ruan Lucas Aug 27 '20 at 16:38
  • What you've written is "please link with SDL2main.lib, located in directory libSDL2.lib". Is there such a directory with that file, relative to your current working directory? I doubt it. Is there a "lib" directory with both "SDL2.lib" and "SDL2main.lib"? If so, you need a whitespace between "lib" and "SDL2.lib". – keltar Aug 28 '20 at 04:30
  • I took a print off my screen so I can see more easily https://drive.google.com/file/d/1vkMIL6tmKmfWTgEBkxosrTAHSTo9MYcI/view?usp=sharing – Ruan Lucas Aug 28 '20 at 23:16

0 Answers0