OpenGL Configuration Problems. Unresolved external signals - c++

I watch "OpenGL Essentials" to learn OpenGL programming. The author writes a framework himself which contains lots of .hpp and .cpp files. To use the framework, I have to compile all files to a single Library.lib file. But there are two questions that I cannot figure it out.
When use the original sln provided by author, it create two lib files, one in a new created folder "Lib" and one in "Debug" folder, It also copy all hpp files in "Library" folder to a new created "include" folder. But this do not happen when I create a new VC++ project by myself. So how should i configure the VC++ project properties to make that happen.
When we use Glfw, we have to include glfw3.lib, and we also need to tell the exe file where to find the glfw3.dll. That's hard to understand. Because, we can compile our framework to lib file, And we also can compile it to dll file. So, Why we need both lib and dll file for GLfw? What's the difference between this two files.

Related

Debugging static library function cpp file in Visual Studio

Being new to making/using libraries, I followed a simple tutorial to build a static library in Visual Studio (2022). I made a solution with 2 projects in it. One that builds a library and one that uses the library. It worked. Then I made an independent project / solution to see if I can use this library independently from the original solution/projects. I put the lib file and hpp/cpp file into new separate folders and set these folders in project properties (Additional Include and Library Directories + the .lib file).
Problem: I could use the functions from the library in this new project but when I tried to step into it with the debugger, the cpp file it stepped into was from the original project. (that's what the path showed anyway.) When I renamed the old project and tried again, VS complained that the file directory has changed and asked me to set the path to it. I did set it to the newly made directory with only the hpp/cpp in it and it was fine. I made another new project for using the library and tried the whole thing again and then the debugger simply could not step into the function, it stepped over it.
My questions: what was going on here? how did the debugger find the original cpp file when Im positive I did not set that path anywhere in the new project? and how do I debug a static library then? Is putting the cpp file next to the header in the include directory not enough?

How to create library that uses some other libraries?

I'm trying to create a graphic library (nothing serious, just to learn stuff). In Visual Studio I have one solution and two projects in it - dll and exe. For window management I use GLFW library. In my own window class I want to have a private memeber of GLFW Window structure. The problem is that my exe project doesn't know what GLFW is - it doesn't know where to find #include <glfw/glfw3>.
My question is - what's the proper way to create such library that uses other libraries? Setting the exe project to include all those libraries doesn't sound like a good idea to me.
Since you are using visual studio, then Microsofts documentation is a great place to get information. https://learn.microsoft.com/en-us/cpp/build/dlls-in-visual-cpp?view=vs-2019 they have a description on DLL’s and how to create them and also how to link DLL’s to projects.
Thanks to #Manuel I figured out how to do it: both - dll and exe projects, have to include libraries' header files.
My solution: in dll I use precompiled headers so all libraries' header files are included in that file with a relative path. In dll project settings I put proper paths so any libraries files will know how to find their headers. What's important is that my exe project includes one header file from my dll and that file include precompiled header so exe project 'knows' everything it needs about libraries.
Thanks again #Manuel for your help!

How to implement and use a .dll or .lib in a Visual C++ Project? [SA-MP Source]

I am trying to learn more about Multiplayer Modifications so i've downloaded the source code of San Andreas Multiplayer.
My problem is that the client project creates a .dll and a .lib files. I've searched on many sites how to implement them into a new project but i just did not find a clear answer.
So i am creating a new Visual C++ project where i need to implement the libraries resulted from SAMP Client compilation. Any help would be great :).
If you want you can join me in this project.
I don't know how SAMP dlls are but in general, this is how it works:
Linker need *.lib files. So you should copy lib files to your default lib directories or create a new directory under libraries of your project and copy them in it.
If the project you want to link have include files too, do what you did for lib files for include files too. Copy them to include directory.
Put DLLs in a directory that your application can reach. This can be your Debug folder or even it can be Windows or System32 directory. Choose where to put them on your own (it depends on many parameters. Pick one that fits you).
This link tells you how to put them in project directories.
That's it. You can call functions of the project you want to use. Tell me if you got problem.

How do I share C++ source code files between projects in Visual Studio?

I'm writing a cross-platform application. One version will work under Win32 and the second on Windows Phone.
I'd like to reuse my C++ core - especially that there are no platform dependencies inside, STL only. I order to do so, I want to use the same source files in two projects: static Win32 library (.lib) and Windows Phone Component (C++/CLI).
How can I configure these two projects to use exactly the same source and header files?
OK, let's take an example. Let's say, that I have project:
MyApp.Library [win32 lib]
myClass.cpp
myClass.h
This library is compiled to .DLL file and then imported in a Win32 application:
MyApp.Win32App [win32 C#]
Since Win32 is not compatible with Windows Phone on the binary level, I cannot use that library directly. But since the library uses only STL, I can create a Windows Phone component, put all its sources there, and build.
MyApp.Component [Windows Phone component]
myClass.cpp
myClass.h
I want these two files to be exactly the same ones as used in the library. How should I organize the project to achieve this effect?
You can add source code from a common location to multiple projects. I do that a lot; I have code in a common directory that is at the same level in the directory hierarchy as most of my project files. It's simply a matter of adding .h and .cpp files from the common directory to your various projects.
I did notice that VisualStudio gets a little cranky and difficult if you use a network drive for common source, so I don't do that. But so long as all of your source code is on local disks, and the IDE knows where to find them, there is no problem having the same source file in very many projects.
one way is to put all .hpp and .cpp files into a seperate folder - call it "Shared".
Then add an additional include Directory inside your solution configuration property - this directory must be a relative path.
Then add ONLY the .cpp files relative from that shared folder into your project
NB! If you have include "stdafx.h" inside your .cpp files in the Shared folder, then comment those out.

C++ Build library and link it

I'm trying to write a program that use FANN Library: http://leenissen.dk/fann/wp/
I downloaded the source code, I opened the .sln project and compiled it. Now: what I have to do? I tried to create a new "console application project", I included the main header
#include "src\include\fann.h"
(I previously copied the src folder in my project folder)
I went on: Project->Properties->Linker->General and I pointed "directories library" to the "bin" folder in which VS compiled the .lib but I still have the error "unresolved external symbol" (the error, of course, is related to some functions that I'm calling in my code). I really don't know what to do, it's my first time I try to do something similar, I think I'm missing something important here...
Try adding your .lib into Project->Properties->Linker->Input->Additional Dependencies.
You'll see combobox, in it 'edit...' and then you'll, get a window where you put the name of your library file. You have to have the library directory set as you did. You have to research what is the name of your library file.
In this forum, they are using 'libfann.lib' name.