How to run and debug multi-file multi-library project in vscode? - debugging

Lets consider a project, with a following structure:
project
--main
--fileX.h
--fileX.cpp
--main.cpp // only file, that guranteed to have main()
--libA
--libA.h
--fileX.cpp
--fileY.cpp If they are outdated/not built - build them first
--libB
--libB.h
--fileZ.cpp
--fileW.cpp
Pretty simple, also lets consider that project must include and link something standart, like OpenGL lib.
On windows, where I came from, there is Visual Studio, and everything was extremely easy and in some kind of "standart" way:
You create solution project. This is like a root, which just incorporates projects, in a single tree
You create projects: main of type "binary" and a couple of libs libA, libB of "library" types (static or dynamic, whatever you require to). That will tell build system how should it glue them together
You edit main settings:
Add external include and lib names, and paths
Add dependencies. main requires libA and libB. That is simultaneously a hint on build order, plus a linkage hint
You add files here and there, code it all, make any changes.
Press debug/run and enjoy. Build system would (re)compile only nesesary files, and link everything needed
Everything involves less than 100 actions, I mean keystrokes and mouse clicks.
VS Commutiny IDE is totally free to use (so no "Use that cool paid IDE" offers could be made in comments and answers)
Now the question. I've installed Ubuntu and vscode, and I am running into wall, trying to setup same project. What actions should be done, so I am able to change any source file in the project, press F5 (Debug), and it would compile and run with same build setup and speed efficiency?
What I've considered?
Makefile: almost same as writing your own shell script. It's like you have to learn whole new language to do small pretty-standart task - build a project. High leven of entrance, to be good at it.
vscode launch.json/tasks.json - another language, with examples availble to compile only single file: main.cpp (or just active file). Hard to create manually, requires good knowledge of internal "env" variables
CMake - another new programming language, different from all others, don't even know how to make vscode and Cmake friends
How a beginner should start C++ debuging with a multi-lib project, without having to waste time maintain that infinite complex build systems?

Related

How do I make a GitHub repository into an exe?

I am new into software developing. I have found this GitHub repository which I plan to modify. Let's just say I fork this repository and modify it. How would I then be able to export it from there. By export it I meant turn all of those files into one windows executable file. Thanks.
In general, building a project is a project-specific task unless the project is written in a language (such as Rust) that has a built-in build tool. If you're unclear about the steps to build a project, you should look in the documentation or the wiki for steps about how to do so, and failing that open an issue asking them to document the procedure for building the project.
Just looking at the project, it does not seem obvious that it should produce a binary executable of any sort since it's written mostly in JavaScript.
Usually you use a compiler to turn source code into machine code (exe files).
As bk2204 mentioned, this project is based on Javascript and Node.js.
Javascript is interpreted instead of compiled, so another program (Node.js) reads the source code and executes it directly every time instead of first compiling it into an exe file. That other program itself may be in an exe file.
The project you have linked is a fork of this project, and that one seems to have a Windows launcher/installer exe file (that probably installs or contains Node.js, but I haven't checked).
That installer is available here in both exe and source code form. So you could modify the launcher and rebuild it, but the main app is not in the launcher, instead it's in all the JS files. You may be able to edit the JS files and just use the same launcher without modifying it. There may be a packaging step required after editing the JS files, to package them into a form that the launcher expects. You would need to run this build step after every time you modify the JS files, to provide the new code to the launcher.
You would have to explore the project's structure and build process to find out the exact steps.
If you're very new that may be exceedingly difficult.
You may want to practice by learning Javascript and Node.js.
You could after that try Java which is compiled, and possibly more powerful than Javascript. Just for fun.
Maybe you could do 30 of these practice projects, then you'll have a chance of being able to modify this project successfully.

React Native - multiple targets

I'm creating a RN app that is meant to be some kind of wrapper. It should have multiple targets (like in Xcode) and all its content (images, text, etc.) should be target dependent. Unfortunately, I cannot find any useful informations about how to achieve this without opening Xcode or Android Studio project and create those targets manually (like here). Is there any other solutions for this?
I was still struggling with described problem but I finally found a solution. It's not easy, needs writing a bit of boilerplate code and looks more like a workaround but I hope it will help someone in the future. What I did is I have completed my wrapper app with the resources for one of my targets so I can have visual effect. In the project's root directory I've created a folder with subfolders for each target. Inside each I have put files (images, source code files, other assets) that are target-dependent. Then I've created bash script that takes one argument - target's name. Based on it, it replaces all the target-dependent files from target's subfolder to the original file's destination in the project structure. In this proces all meta-data informations are also replaced so after firing .sh file I can build the app and upload it to both stores. It's really time consuming to create all these apps separately and publish them and it's maybe not the best solution, but at least it works!
On android, you can edit build.gradle files, java or properties, without having to launch Android Studio (which simply uses Gradle)
You can build different type flavours by only changing app/build.gradle
On iOS, that's another story. Project file (.pbxproj) is a mess,and other Workspace/Scheme files are not easy to read or script. So XCode is the way to Go.
I tried to have dynamic target & Info.plist, there are tools to script that like PlistBuddy
in the end, I saw there are many ways to launch a React Native app for developpers. Some prefer the command line, and only VSCode.
Others want to play with native IDE.
By the way, native IDEs are VERY useful.
e.g. : you want to fine-tune your application performance, using XCode view hierarchy debugger or android Studio Layout Inspector (and be sure you don't use to many views), or use any other performance tools these IDEs offer...
In the end, I used react-native-config along with multiple almost similar configs (Info.plist < target < Scheme for each), here's a post giving an overview of the setup.

Is there a way to work on multiple projects in CLion?

I'm looking for a way to work on multiple projects in parallel in CLion IDE.
For now I can only work on each project in a window at a time, but I'm looking for a solution similar to Eclipse IDE (see below) - being able to see my different projects' directories on a side bar and choosing the one I want, compiling it by itself, etc.
Is there a way to do it?
Yes: CLion doesn't allow you to open multiple projects from the menu because it uses the CMake system, which is script based.
However, CMake is quite capable of encompassing multiple projects, and CLion will correctly parse your CMake file and show all relevant directories in the project explorer.
Example
To do this, just like in Visual Studio, you need a parent "solution" and one or more child "projects".
Here is a simple CMake example in which "my_solution" references two child projects, "my_application" and "my_library". Here, my three folders are arranged:
xxx/my_solution/CMakeLists.txt
xxx/my_application/CMakeLists.txt
xxx/my_library/CMakeLists.txt
And xxx/my_solution/CMakeLists.txt simply reads:
cmake_minimum_required(VERSION 3.7)
project(my_solution)
add_subdirectory("${PROJECT_SOURCE_DIR}/../my_library" "${PROJECT_SOURCE_DIR}/my_library_output")
add_subdirectory("${PROJECT_SOURCE_DIR}/../my_application" "${PROJECT_SOURCE_DIR}/my_application_output")
Note that it is also permitted to put my_application and my_library within the my_solution directory, as in Visual Studio.
No. CLion either:
opens a new window with the other project you want to work on
closes your current project and opens the new one in the current window
as you can see in the documentation. I think this is wanted in their design; probably to maintain CLion fast and reactive...
Adding some visual clues based on the answer from #c-z
This is how my project structure looking -
This is how my root level CMakeLists.txt is looking -
Finally, this is how my sub-directory level CMakeLists.txt is looking -
NOTE:
You may choose to remove the outer level main.cpp file (I've deleted it)
Also, you can remove the project level executable to remove it from the run configuration.

OpenGL SDK How To Create New Projects With Premake

I have recently begun the process of learning OpenGL to start making some Graphical applications using C++. I have installed the OpenGL SDK and I am able to build the projects properly on that. However, on the OpenGL SDK site there is little to no information what-so-ever on how to create new projects using the elements of the SDK, such as freeglut etc. I have Premake 4.0 and I understand I have to do something with the lua files, I do not know lua however and am not sure how to use the Lua files to create a new project. So could you help me out? Im using VS2010, should I create the project, then do something with premake? Or create some sort of lua file, then use premake on that? Any help would be wonderful because I am very lost, and would really like to get started with OpenGL. I have experimented a lot with this, such as copying the lua files from the sdk, but that came with no luck.
If you are not familiar with Premake4, then I strongly advise you to just use Visual Studio projects directly. If you're having trouble with that, then please amend your question with exactly what you did, and exactly the error messages that Visual Studio gave you when attempting to build. You should include:
The include paths. The full set of include paths, including full absolute directory names (including the path of your project and solution files).
The static library search paths.
The static libraries you are including.
The defines you are building with.
Note: If you don't know what any of these are, then you need to stop and learn a lot more about how C++ projects work. You need to understand how compilers deal with include paths, static libraries, #defines, etc.
If you are not familiar with Premake4, and you still want to use Premake4 with the SDK, then you first must become familiar with Premake4 without the SDK. I could give you an entire premake4.lua script that you could just plug in, change a few lines, and everything would magically work (and if you want that, you could look at how the SDK's examples are built. Specifically examples/premake4.lua). But if I did that, you wouldn't learn anything. You'd just be copy-and-pasting code, without having the slightest understanding of how it works.
So instead, I'm going to tell you what steps you should take to learn how to use Premake4.
Step 1: Hello World, Premake-style. You should make a single .cpp file that is a Hello World application. It just has a standard main function that prints "Hello World" to the console. That's the easy part.
The hard part is the Premake4 script. Rather than creating a Visual Studio project directly, you are going to write a Premake4 script to build that project for you.
The Premake4 documentation can walk you through the steps of making your first solution and project. You will of course need to add files to that project. You should also learn how to use configurations, so that you can have a Debug and Release build. The Debug build should have symbols, and the Release build should be optimized.
Step 2: Multiple projects. Here, you have two .cpp files: test.cpp and main.cpp. In test.cpp, place a function that prints something. The function shouldn't take parameters or anything. In main.cpp, you should have the main function that calls the function defined in test.cpp. There should also be a test.h which has a prototype for the function defined in test.cpp.
The trick here is that you aren't compiling them into the same executable. Not directly. You want two projects: one named test and one named main. The test project should be a static library, which compiles test.cpp. The main project will be the actual executable, which compiles main.cpp. Both of them should include test.h in their file lists.
Here, you're learning that solutions can have multiple projects. The two projects have different file lists. Each project can have a separate kind, which determines the type of build for that project alone. The test project should be a StaticLib, while the main project should be a ConsoleApp.
You will also need to learn to use the links command to link them together. The main project should use links to specify test. test does not need to link to something.
Step 3: Mastering directories.
Here, you're going to do the same thing as Step 2. Except for one thing: put test.h and test.cpp in a different directory (a subdirectory of the current one). You also want a test.lua file in that directory, which you will execute from your main premake4.lua file with a dofile command. The test.lua is where you define your test project. You can call dofile on the test.lua file anytime after you have created the solution with the solution command.
Note that the main project will need to change the directory where it finds test.h. You will also need to use the includedirs command in the main project to tell the compiler where to search for the test.h header you include in main.cpp.
Step 4: Back to the SDK. At this point, you should now be familiar enough with Premake4 to look back at the instructions I pointed you to and understand them a bit better. Then, just do what the instructions say. When it tells you what the first line of your script should be, make that the first line of your script. Put the UseLibs function where it says to put them; it even gives you an example of where it goes. Think of UseLibs as a fancy combination of links and includedirs.

How do I create a makefile from a Visual Studio solution file?

I have a Visual Studio project that uses a solution file to build it. I want to generate a makefile so that I can build it using the makefile instead of the solution file. (The reason I need to do this in case you are wondering is that I am incorporating my project into a larger software system that uses makefiles to build, and I want to be able to build the whole thing using the makefiles.)
Is there a way to automatically get the information from the Visual Studio solution and convert it into a makefile format, or do I need to do that manually?
This used to be possible in VC6, it had an option to generate a makefile from a .dsp project file. No more, the build process has changed too much to make this achievable.
Not a real problem, you can have the makefile invoke the vcbuild.exe tool, it builds a .vcproj project. Important switches you'll want to use in your makefile:
/clean: use that in your clean: target
/rebuild: use in your rebuild: target
/nocolor: makes build output look battleship gray like other build tools
/platform: selects the configuration you want to build (e.g: /platform:win32)
For example:
vcbuild /platform:win32 example.vcproj release
Note that the build system got a major revision in VS2010, you'll use msbuild.exe instead to build the .vcxproj project.
Although I never used it, this might be an alternative. It's rather old and might not work well for new projects. It used to come with mingw but (don't know why) not anymore. Offtopic: Personally, if the project is not enormous, I would go with manually writing a Makefile.
Good advice - Avoid wasting a couple of days on tools for a job that'll take a few hours at most. They guy who built my first house had one 30 year old table saw and built the whole house iwth it. I now have at least 10 saws and never build anything.

Resources