Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Compiling with Batch File Lnk2019 Error  (Read 965 times)

0 Members and 1 Guest are viewing this topic.

Kane_Madness

  • Newbie
  • *
  • Posts: 4
    • View Profile
Compiling with Batch File Lnk2019 Error
« on: March 12, 2018, 02:22:22 am »
Hello All,

I am trying to learning the in and out of compiling from the command line (I feel its a good thing to know). I want to get a simple SFML test case working but am running into a snag. Currently, I think I am linking to all the static libraries correctly but ending up with a Link 2019 error. I dumped all the necessary files in a directory named SFML at the same level as the sfml_test.cpp.  I am using VS2014 32 bit and downloaded the 32 bit SFML tools. Below is the Test case, the  batch file and output error. I went through the tutorials and can get it to compile in Visual Studio. I went through the forums but couldn't find an answer to the command line compile. I must be missing a dependency but I am not seeing it, Thanks!
CPP file: (mostly commented except for the first line call to render window)
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Test");
    //sf::CircleShape shape;
    //shape.setRadius(40.f);
    //shape.setPosition(100.f, 100.f);
    //shape.setFillColor(sf::Color::Cyan);
    //while (window.isOpen())
    //{
    //    sf::Event event;
    //    while (window.pollEvent(event))
    //    {
    //        if (event.type == sf::Event::Closed)
    //        {
    //            window.close();
    //        }
    //    }
    //    window.clear();
    //    window.draw(shape);
    //    window.display();
    //}
    return 0;
}
 

Batch file for compiling:
@echo off
set INC_SFML="SFML\include"
set LIB_SFML="SFML\lib"
call C:\"Program Files (x86)"\"Microsoft Visual Studio 14.0"\VC\vcvarsall.bat
cl /EHsc /I %INC_SFML%  test_sfml.cpp
link /MACHINE:x86 /SUBSYSTEM:CONSOLE /LIBPATH:%LIB_SFML%^
 sfml-system-s.lib^
 sfml-window-s.lib^
 sfml-graphics-s.lib^
 opengl32.lib^
 freetype.lib^
 jpeg.lib^
 winmm.lib^
 gdi32.lib^
 /OUT:test_sfml.exe test_sfml.obj
cmd/k

Output errors:
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test_sfml.cpp
Microsoft (R) Incremental Linker Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test_sfml.exe
test_sfml.obj
test_sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main
test_sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function _main
test_sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
test_sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class sf::String const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABVString@1@IABUContextSettings@1@@Z) referenced in function _main
test_sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
test_sfml.exe : fatal error LNK1120: 5 unresolved externals
Microsoft (R) Incremental Linker Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : warning LNK4001: no object files specified; libraries used
LINK : fatal error LNK1159: no output file specified
'freetype.lib' is not recognized as an internal or external command,
operable program or batch file.
'jpeg.lib' is not recognized as an internal or
external command,
operable program or batch file.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Compiling with Batch File Lnk2019 Error
« Reply #1 on: March 12, 2018, 07:32:36 am »
You forgot to define SFML_STATIC.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Kane_Madness

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Compiling with Batch File Lnk2019 Error
« Reply #2 on: March 13, 2018, 01:31:35 am »
Thanks! Unfortunately I am not sure where do I put the define? is it in the batch file or in the .cpp? I tried
cl /EHsc /I %INC_SFML% /DEF:SFML_STATIC test_sfml.cp
but it still hangs, I also put the /DEF:SFML_STATIC in the linker line as well and same issue. I also tried a #define SFML_STATIC in the .cpp file.

Thanks

Kane_Madness

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Compiling with Batch File Lnk2019 Error
« Reply #3 on: March 16, 2018, 11:22:52 pm »
So a missing / was the end product of my mad desire to compile from the command line. For posterity here is the actual necessary lines to compile with dll's. Paste it into a batch file and it should work.
set INC_SFML="SFML\include"
set LIB_SFML="SFML\lib\release"
cl /EHsc /I %INC_SFML% test_sfml.cpp^
 /link /LIBPATH:%LIB_SFML%^
 sfml-graphics.lib^
 sfml-window.lib^
 sfml-system.lib
 

-Regards
Kane

 

anything