Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have successfully downloaded Raylib, and added "C:\Users\CENSORED\source\repos\hello world\vcpkg\packages\raylib_x86-windows\include" to the additional include directories. Visual Studio recognizes both the command InitWindow() and CloseWindow(). I know this because it tells me what parameters I need to enter, but despite this, attempting to run produces this error: "error LNK2019: unresolved external symbol __imp_InitWindow referenced in function main". Here is my code:
C++
#include "raylib.h"

int main() 
{

	InitWindow(800, 600, "Pong");

	CloseWindow();

	return 0;

}


What I have tried:

I have tried my code in different project types (the current one being empty project), reinstalled Raylib a couple times, changed the path to "C:\Users\CENSORED\source\repos\hello world\vcpkg\packages\raylib_x86-windows\bin" and "C:\Users\CENSORED\source\repos\hello world\vcpkg\packages\raylib_x86-windows\lib", and installed Raylib with Vcpkg.
Posted
Updated 14-Jun-22 3:20am
v2

You need to add the location of the library(s) to the "Library Directories" item of the "VC++ Directories" section in the Project Properties. You then need to add the name of the .lib file to the "Additional Dependencies" item in the Linker Input section.
 
Share this answer
 
v2
Comments
Great Goldengoat 13-Jun-22 11:42am    
What, if anything, do I put in the properties for source.cpp? I'm still getting errors, and suspect that might be the problem.
Richard MacCutchan 13-Jun-22 11:53am    
Given your original message you already have your C++ source included. But we cannot guess what the latest problem is without the error messages.
Great Goldengoat 13-Jun-22 11:59am    
The error is exactly the same. I have "C:\Users\CENSORED\source\repos\hello world\vcpkg\packages\raylib_x86-windows\lib;$(LibraryPath)" in Library Directories, and "raylib.lib;%(AdditionalDependencies)" in Additional Dependencies.
Richard MacCutchan 13-Jun-22 12:44pm    
At a guess the path or the library name is incorrect. Without more information it is impossible to guess.
Great Goldengoat 13-Jun-22 13:01pm    
what information do you want? I'm happy to provide it!
I would do three things : 1 is add a trailing slash after ...\Lib and before the semicolon so it looks like this : ...\Lib\;

2 : try using the pragma form of specifying a library to link with. That would like this :
#pragma comment( lib, "raylib" )
This is done in your source code file. I like this form because you can use different libraries based on ifdefs for various things like debug or release, 32-bit or 64-bit code, etc...

3 : verify that the file raylib.lib exists in the directory you specified.
 
Share this answer
 
There seem to be many possible combinations to use raylib with Visual Studio.
If you compile the source code from github.com/raysan5/raylib with Visual Studio, various libs are created.
This are the Versions generated after running the Solution:
...\build\raylib\bin\Win32\Debug        8.166.536 raylib.lib
...\build\raylib\bin\Win32\Debug.DLL      158.138 raylib.lib
...\build\raylib\bin\Win32\Release      8.182.538 raylib.lib
...\build\raylib\bin\Win32\Release.DLL    158.138 raylib.lib
...\build\raylib\bin\x64\Debug          9.764.574 raylib.lib
...\build\raylib\bin\x64\Debug.DLL        154.390 raylib.lib
...\build\raylib\bin\x64\Release        5.008.812 raylib.lib
...\build\raylib\bin\x64\Release.DLL      154.390 raylib.lib

It's also possible to download the game-premake-main.zip, but I haven't tested that.

The examples are structured in such a way that the path for the linker is under

Properties/Linker/Additional Library Directories

is stated as follows:
$(SolutionDir)\build\raylib\bin\$(Platform)\$(Configuration)\

As far as I can tell it should work for all examples and combinations.
Possible procedures can also be found here:
https://github.com/raysan5/raylib/wiki/Working-on-Windows

Unzip the raylib-game-template-main.zip file or load the project with git.

Under Linker/Input/Additional Dependencies are these libs entered:
raylib.lib; opengl32.lib; kernel32.lib; user32.lib; gdi32.lib; winmm.lib; winspool.lib; comdlg32.lib; advapi32.lib; shell32.lib; ole32.lib; oleaut32.lib; uuid.lib; odbc32.lib; odbccp32.lib


I was able to compile the program presented above
C
#include "raylib.h"

int main() 
{
  InitWindow(800, 600, "Pong");

  CloseWindow();

  return 0;
}

on the basis of a simple Win32 console application created by VS. I only added raylib.lib and winmm.lib to the linker.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900