This is my first time with Embarcadero RAD Studio (C++, not Delphi) and, despite of many searches on its site and the rest of Internet, I'm still confused with some concepts.
My goal, by now, is to set a OpenGL Core Profile and go on with OGL stuff (which I'm acquainted with). With other IDE/Compiler I'd add the opengl32 library, use wglCreateContextAttribsARB and glew.
Digging into Embarcadero files I find C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\win32\release\psdk\opengl32.lib, C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\win32c\release\psdk\opengl32.lib (note the 'c' after win32, what's that?) and C:\Program Files (x86)\Embarcadero\Studio\20.0\lib\win64\release\psdk\opengl32.a
So I suppose I could just "Project->Add to Project..." the library, instead of "import" from Windows system as it seems was needed many years ago. But I'm confused because RAD may add the required libs on its own, at least for controls, right?
But I've meet with ".pas" files, which seems to load anything needed. Actually, the C:\Program Files (x86)\Embarcadero\Studio\20.0\source\rtl\win\Winapi.OpenGLext.pas seems enough, so I could avoid glew. My confusion is that I don't know if a ".pas" file can be used (and how) for VCL C++, not Firemonkey, not Delphi.
I have not be able to find wglCreateContextAttribsARB, nor a replacement for setting a Core Profile context.
Summarizing:
Do I need to add system libs? How?
How to use ".pas" files?
Which is the difference between win32 and win32c dirs?
How to set a OGL Core Profile context? I mean, should I go with the route of retrieving a function pointer to
wglCreateContextAttribsARB or RAD provides another way?
Does RAD provide for C++ a replacement of glew?
1.Do I need to add system libs? How?
Normally yes. unless you are using a component that has taken care of adding the library. In Win32 you have to use #pragma link "opengl32.lib" and in win64 you have to add #pragma link "opengl32.a" to your cpp code.
2.How to use ".pas" files?
You do not need to add the files in the source directory to your project. Embarcadero is nice enough to include the source code for most of its components with the product. This is so you could understand how it works and if you need to change some behavior you can create a new class derived from the class that you want and override the function in question. In general C++ builder allows adding Pascal units to C++ project and it will take care of creating the header file automatically. But in your case it is not necessary.
3.Which is the difference between win32 and win32c dirs?
C++ builder comes with 2 32 bit compilers for Windows. One is clang based and supports C++14 and the libraries that have been compiled with it are in win32 directory. The other one is the classic compiler and the libraries that have been compiled with it are in win32c directory. Unless you have checked the "Use Classic Compiler" in project settings, you don't have to worry about it.
4.How to set a OGL Core Profile context? I mean, should I go with the route of retrieving a function pointer to wglCreateContextAttribsARB
or RAD provides another way?
I'm not aware of any components that RAD studio may provide. You should search https://torry.net/ or http://www.delphipages.com/ or many more places that exists out there for a component that helps you whith what you need.
5.Does RAD provide for C++ a replacement of glew?
What is "glew"?
Related
I am developing a project on C++ which relies on many of third-party libraries (*.lib files and *.h files). I store these libraries in a folder which is not dependant to project, like C:/thirdpartylib. Relative paths is not an option, since it becomes way too long. I have defined connections to libraries in linker setting and in general C++ settings.
But when I pass the project to supervisor he has to reset all paths to libraries to match his environment. We use git, and the project file is being tracked. He stores thirdparty libraries in another way than me.
Is there any way to make a project more portable? Maybe it is possible to store paths in some sort of config files?
As #gaurav says, the way to deal with this in Visual Studio is with property sheets. It's unfortunate that this term is used for two different things in VS, but I guess they just ran out of names (spoiler alert).
These are very powerful, once you learn how they work, and they're just what you need here because they let you define macros, and these macros can in turn be used in the rest of your project to refer to the (volatile) location of your various libraries. This is a trick that everyone who uses VS should know, but it seems that a lot of people don't.
I don't think it's worth me trying to walk you through the mechanics of setting one up here because Microsoft already document it in the Visual Studio help file. Suffice to say, you do it in the Property Manager, that should help you track down the relevant information.
There is also an excellent blog post here which I recommend you read before you do anything else:
http://www.dorodnic.com/blog/2014/03/20/visual-studio-macros/
It's also on Wayback Machine here:
https://web.archive.org/web/20171203113027/http://www.dorodnic.com/blog/2014/03/20/visual-studio-macros/
OK, so now we know how to define a macro, what can we do with it?
Well, that's actually the easy part. If we have a macro called, say, FOO, then wherever we want to expand that macro in some project setting or other we can just use $(FOO). There's also a bunch of macros built into the IDE as listed here:
https://msdn.microsoft.com/en-us/library/c02as0cs.aspx
So, you, I imagine, will want to define macros for the include and lib directories for each of your external libraries and you can then use these to replace the hard-coded paths you are currently using in your project.
And that, I reckon, should sort you out, because the definitions of the macros themselves are stored in a separate file, external to your project file, and different users / build machines can use different files. IIRC, these have extension .props.
Also, you can define a macro in terms of another macro or macros, and that makes the job easier still.
So, who still thinks that Microsoft don't know how to create a build system? Visual Studio is a fantastic piece of software once you get used to it, there's just a bit of a learning curve.
The way to go for large project is to use a package manager. There are some good options out there. Perhaps in windows and visual studio you can use vcpkg or NuGet unmanaged.
If you cannot use a package manager for some reason, the next thing to do is to commit all the dependencies to the GIT repo. If you only target windows platforms like windows 8 or 10 and want to support only VS2017 then committing the compiled dependencies is not a problem. The downside is that the repo will become huge.
For a tiny school project the latter option is viable.
Question:
Once my code is working how should I prepare my files so that a stranger on a different computer can compile it without difficulty?
Additional Details:
I am sending a code sample to a company as part of an application so obviously an elegant solution would be better (i.e. minimise number of files required etc) and no work should be necessary by the stranger at the other end.
Although I am only using one simple library, even so I need to set include directories, include lib files, images, dll files etc so that it all compiles correctly.
If it matters, I am using Visual Studio 2015 and the simple library is SDL.
Sorry if this is a duplicate, I was sure that this question would have been asked before but if it exists I just don't know the correct terminology to find it amongst the noise.
Apologies if this is overly simplistic, but you might want to bound the scope of your project by deciding which computers you want to support, and build your code yourself on those platforms, in advance, just to be sure.
List the supported platforms in your release notes, including any platform-specific instructions or information (which VC++ versions, which C++ versions, which OS versions, which DLLs, directory structure, etc.).
You may have to stick some "#ifdef"s and such in your code, but only by building on a particular platform/configuration will you really know for sure.
You can use properties/props files in your VS solution which sets the paths to includes and precompiled libs, then reference the build variables in your project files.
To compile on another machine, you just need to change the values in the properties files.
I'm trying to write my first game in c++, and I want it to dynamically load everything from files. This includes the enemies, and I was wondering if there was a way to dynamically include their code at runtime, instead of linking the on compile, so that the levels are easily interchangeable. Lua might be an option but I have no clue where to start, and dll seems to be Windows-only (and I wouldn't know where to start there anyway). Can anyone help with this?
tl;dr I want to link in code to my c++ game at runtime.
For the Lua approach you first need to choose the version first. Right now there is the major version 5.1 and 5.2. My previous work was using 5.1 and for my new project I decided to update to 5.2, however I found that my favorite script wrapping tool (SWIG) does not work with 5.2. Just something to decide at the beginning, because you do not want to get a version working and then have to change it.
Lua comes with makefile build environment. My first experience of trying to build on Windows was a bit of a nightmare, did not appear to just run out-of-the-box, so I opted to create my own Visual Studio project at the time, and just include all the .C files in the project. There are two files which need to selectively included/excluded depending on how you intend to compile: lua.c and luac.c. If you are planning to embed Lua in your app, then exclude both of these files; they both contain a main() function and are designed to build console apps. Include all the rest of the C files in your project.
You should be able to compile easy from this point.
When you include the headers of Lua, keep in mind that the functions are C functions so if you are including them from C++ you need to wrap the file inclusion inside of: extern "C" {} - example: C++ Lua 5.1 Issue
Wrapping your interfaces in another topic and there are lots of resources available. My favorite is SWIG but there are lots of options, including hand coding the conversion of your C/C++ -> LUA -> C/C++ code. Would recommend just focusing on getting the first part working first, get the interpreter embedded so that you can run a "hello, world!" script from Lua inside your app.
So going by your requirement of crossplatform use and dynamic linking, what you're probably looking for is an environment like QT which has QLibrary: https://stackoverflow.com/a/9675063/453673
But https://softwareengineering.stackexchange.com/questions/88685/why-arent-more-desktop-apps-written-with-qt
MingW is the open-source equivalent for Visual C++, so it can help you writing code for Windows (though if I had a choice, I'd directly use Visual C++). The way dll's are loaded in Windows is somewhat similar to the way they're loaded in Linux, so you'll be able to write code with #ifdef's to do conditional compilation. I've written one such program a couple of years back.
To load a shared library(always with .so as suffix) under Linux, you could use dlopen(), dlsym() and dlclose()
I want to use simple plotting functions in my C++ code. Presently I am using Qt5 with VS2010 c++ compiler. I came across this library called koolplot. But I cannot buid it with VS2010 from its source files. I am opening vs2010 cmd and running nmake...It shows winbgim.h missing..I copied that header in MinGW include folder and ran it ...now it shows "Plotdata.h:warning: 'typedef' was ignored in this declaration" Please help...if any one knows a simple plotting library running with VS2010 please suggest..
According to its website, Koolplot is designed for the MinGW/gcc toolchain - you'll have to do a bit of leg work to get it to compile on Visual Studio, though I don't know specifically what you'd have to do without taking a closer look.
Also, the library seems to do its own window management and the like, so I'm not sure how well you'll be able to integrate it with Qt.
koolplot needs WinBGI library (BGI = Borland Graphics Interface?).
I have changed it to use native Win32 using VS2008:
http://www.tu-chemnitz.de/~heha/hs/koolplot-heha.zip/
It's still incomplete as a good Win32 implementation would implement koolplot in a DLL which self-registers a Window class, and has both C and C++ interface. Moreover, koolplot as-is doesn't support multiple scales, finer plotting options, GDIplus, and fast data update, so it's not the right thing to write an oscilloscope program.
It's C++ code is also outdated as there are lambda functions available now.
However, good integrating into Qt is another task.
everybody, I am getting started develop a C++ project and in this project I must use some opensource project have several dll file. Then I have a question "How to build C++ project embed all dynamic link library in exe file?"
Thank for help!
Note: Sorry, I forgot that I'm using visual studio compiler on x86
There is no general answer to your question. It depends whether you need it to be cross platform or not.
However, since you're mentioning "visual studio compiler on x86", I bet you're targeting Windows. In such a case you have two options:
the official and recommended way: embed your dlls as resources in your executable; then when your program starts you extracts these dlls somewhere on the disk as temporary files (beware file permissions) then you use LoadLibrary + GetProcAddress
the hackish way: you write a PE executable loader in order to circumvent the fact that the Windows API only offers a way to LoadLibrary from a file on disk. By writing your own PE loader you'll be able to load a dll directly from a memory stream. Then again, I'm just mentioning it for reference but it's by no means something one should do
Finally, you need to comply to the license chosen by those opensource projects you're using. My answers gives technical directions about how to achieve your goal; it doesn't mean the license of the project you're using allows you to do so.