Clion - Can I debug across projects? - c++

I have the following setup for my C++ application:
Project "Common" with 6 cpp source files. One of these cpp sources is named dataclasses.cpp. The output of this project is libgeneral.dylib, to be used in the next project below.
Project "Algorithm" with only one cpp source file. This project uses the libgeneral.dylib from above and outputs another dynamic library named libalgorithm.dylib, to be used in the project below.
Finally, project "CLI" has one cpp file source file and uses libalgorithm.dylib created above. It creates the executable cli.
(I created this structure because I plan on using parts of the code base in different applications in the future. In my mind, this structure keeps things modular and clean.)
I am able to compile/build everything and run the executable with a 0 return code. However, there is a computational error in the output triggered by running cli against certain data. I suspect the error is in dataclasses.cpp. So my plan was to open the file dataclasses.cpp in project CLI and mark a breakpoint at the right spot, and then run debug in CLI. But when I attempt that, the breakpoint appears as an empty white circle with a diagonal line and a message
The breakpoint will not currently be hit. No executable code is associated with this
line.
Yet this is not true, the line I have chosen is definitely an executable line.
Note that I am able to successfully use breakpoints in the one source file that is used in project CLI.
CLion version: 2022.2
MacOS 12.2.1
Question: How can I debug dataclasses.cpp while running in project CLI? I would prefer to not add any new files in project Common; I want to keep this as a tightly defined library. Note that before the data reaches the relevant part of dataclasses.cpp, it has gone through multiple manipulations in the code within projects Algorithm and CLI. I know that ideally I should write test cases for everything in dataclasses.cpp, but I would like to solve this known issue quickly first.
A similar question was raised here, Can I debug libraries (DLLs) directly using CLion?, and the answer suggesting creating an executable in the library project, which I'd like to avoid. Plus the post is six years old and I'm hoping things have changed.

Related

How to use the GLOP Linear Solver with Visual Studio 2017 [C++]

I've been trying to get this to work for a while but cant figure it out for the life of me.
Here's my situation right now:
I have a Visual Studio project (and solution) up and running, and would like to modify it as little as possible. I now feel the need to use GLOP Linear solver within my project, and was wondering how I'd go about doing this.
The code that I've written that uses GLOP works perfectly as a standalone .cpp file :
[ this .cpp file is placed in the same directory as the resources for GLOP, and compiles and runs perfectly after creating and using the make command as mentioned here https://developers.google.com/optimization/introduction/cpp
]
I would now like include this code in my project, and run it as a part of my project rather than as standalone code. As I'm currently using MSVS 2017, I was wondering how I'd go about doing this as the current tricks I've used (copying and pasting all the resources for GLOP in the project folder, among other things) don't seem to be working and my error list keeps growing, and using the make commands is obviously not an option as the code needs to embedded amongst other code.
Please explain to me like I'm five years old - what files are supposed to go where, what linkages am I supposed to perform and what other.
I suppose you have already downloaded and extracted the binary archive:
or-tools_VisualStudio2017-64bit_v6.8.5452.zip
When running the make rcc command to build a C++ example, you should have spotted the needed flags to use in your project.
First you need to configure your project to add the include directory:
Configuration Properties>>VC++ Directories>>Include Directories
Then you must add some preprocessor flags e.g. -DUSE_GLOP
note: you can find here what we use in the Makefile:
Configuration Properties>>C/C++>>Preprocessor>>Preprocessor Definitions
Then add the static library libortools.lib to your linker:
Configuration Properties>>Linker>>Input
Note: Images come from various sites on the internet please adapt it.

Quickly create and run new C++ files in XCode

I'm learning c++ and I'm building simple, procedural programs that only consist of the one file (where int main() is located). I find it fairly tedious to create a new project in Xcode for each file and I was wondering whether there's a way to either have multiple files in a project and choose which one to compile, or a faster way to create and run/build C++ files in Xcode. I'm currently just commenting programs out as I go and I'd appreciate someone suggesting a better way. I'm open to using Sublime and Command line as well
You can choose which files to build and run by changing the Scheme.
I am assuming that you are creating a Console Application / target for each set of files you want to run separately.
go to Product->Scheme and change the Scheme.
Then Build and Run your files.
I think command line is the way to go here. You can easily edit the files in XCode (open -a Xcode file.cpp) and compile and run it from the terminal (clang++ -std=c++11 -stdlib=libc++ -o name_of_executable file.cpp).
An alternative to having multiple targets in XCode is to have one command line target and change the file that you compile as a part of the target. In XCode 5 you can show the Utilities panel (top right icon - Hide or show the utilities) and check/uncheck whether a selected file belongs into a target (in the window titled Target Membership). That way you can have a number of files, each having its main() but you always have only one file selected as a part of the target.
You can create a single project file, then create a new target for each new app instead of a new Xcode project. I'm not sure if that meets your needs or not.
Although if all you're doing is compiling and running a single file, why even use Xcode? Just go to the command line and compile and run it directly, if that's easier. You can invoke clang directly. See the man page for details.

Xcode run script during build

I'm working on a project which has a SQLite database, built by running "sqlite3 [db filename] < [schema filename]" from the Terminal on Mac OS X. I'd like to learn more about the projects system in Xcode, and ideally get it to run this Terminal command automatically when I build the project, additionally copying the created database into the output directory of the C++ project. I've been able to do similar things with Visual Studio before, and I get the impression from the options presented that I can do the same thing in Xcode.
I've added an external build target with the database schema files inside it (so they get source controlled too) and at first it was running with errors that too many arguments were being passed. However, I put single quotes around the arguments and now it runs. But I don't see any output. The file is not generated in the directory I set and I can't find it anywhere else. I was wondering if it took the single quotes as a single argument to sqlite3, but I can't find anything named that either.
I keep finding tutorials such as this one: http://b2cloud.com.au/how-to-guides/precompilation-run-script-in-xcode-4 but it appears that Xcode has changed since they were written and I'm having no luck on 5.0.1. I can't seem to get it to run shell scripts, (hopeful for a workaround) can't find the output of what appear to be successfully run commands, and cannot add Aggregate/External Build Tool projects to the dependencies of my code project, so even if I had it working, it would not rebuild the database with the source code.
I'm more after an outline of the best way to do this in 5.0.1, because I suspect my entire approach may be wrong here.
Thank you for your time.

How can codeblocks go from finding header files to not being able to find them, when none of the source code has changed?

Why would a project be able to compile and find the necessary header files, and then I add a line that it cannot find, it does not compile, I remove that line (the code now looks exactly as it did when it compiled the first time) and now suddenly it cannot find the header files that it could find only a moment ago? I did not change any of the file structures, absolutely nothing changed other than adding a line, removing it, and everything is broken.
I have followed every instruction in the Ogre3D tutorials up to building the first tutorial. Everything works perfectly fine and the first tutorial compiles and runs. So I decide to see if I can get a different tutorial to do the same thing, but alas the compiler throws an error: No such file or directory when looking at the line #include "Ogre.h". So I go back to the first tutorial's framework, I include all the lines and it still compiles as expected and then I decide to remove all of the source files and everything, and I take the very first include directive from the BaseApplication.h, the line is #include <OgreCamera.h>, and I put this lonely line in a single file main.cpp and attempt to compile this 1 line program. The same error occurs, it cannot find OgreCamera.h! What??
So what is so special that the tutorial framework compiles but when I try to do basically the exact same thing it throws a fit.
Update
Even stranger things are happening now... I added the line #include "Ogre.h" to the tutorial framework's BaseApplication.h file, it cannot find Ogre.h. So I remove that line and try to compile the program (which compiled not more than 10 seconds ago) and now it no longer can find OgreCamera.h! But it has literally not changed at all in any shape or form that I can tell. This is confusion of maddening proportions now!
Where the header files are resolved from is not defined in the code itself, but in the IDE and/or code::blocks project preferences. This tutorial is more relevant for setting up the search directories for Ogre header files.
If it was working a short while ago and not now, I would suspect you have probably made a simple mistake like switching from Debug to Release, having only configured the search directories for Debug build in the project properties. (Clicking build options defaults to selecting Debug rather than all configurations). Try to re-add the Ogre directories in both Debug and Release builds.
Code::Blocks also lets you add search directories globally for the IDE, in the compiler and debugger settings for commonly used libraries. You can also create a global variable for the Ogre SDK location to make it simpler to add to each new project. (#ogre.include), rather than adding the full/relative path.
I believe I know what I have done to myself here.. and recreated the problem
I followed the tutorials and setting up an application to the letter, and was having some other problem when I decided to copy the entire project I had already made doing the tedious setup things necessary. Without realizing that copying the entire project by simply copy-pasting the directory does not carry the tedious setup things necessary. And so, probably without paying attention to the "Target is up to date." build message, assuming it compiled I changed the files, it did not compile as expected, and then changed them back to their original state, and it still did not compile because they were no longer up to date.
I am going to remember this... for a long time.

Adding a text file to an exe generated by PyInstaller

I have a rather interesting problem I've been trying to find a way to solve, and as of the moment, I have not found a solution to. I currently have built a GUI program using Python, and more specifically using Tkinter, which will generate a file with a list of commands to be repeated by my program in the specified order while waiting however long is specified. It's basically used to create a macro, which is recorded in a file and can be ran later using another function in the program.
What I would like to add to my program is a manner in which to create an .exe file, which is a standalone file, that can run a script from within it. The reason I can not find a good way to do this though is because I need for it to be created on the fly. What I was thinking I'd like to do is generate an .exe(Standalone macro exe) with PyInstaller ahead of time, and package this in to my main .exe also using PyInstaller. When you choose the option to create a standalone macro, it would proceed to get the .exe(Standalone macro exe) which I had packaged in to my main .exe from the directory in which it was unpacked in to when the program was run, copy it to the desired location for the standalone exe to be saved to, and then copy the script the user wished to be run as a standalone and package it in to the standalone exe.
I have no idea how to go about this, because I'm not sure exactly how PyInstaller puts the files in to a .exe when it packages it. Because of that, I wouldn't know how to add a file to an existing .exe using python.
Basically what I need help with is how I might go about adding a text file to an .exe generated by PyInstaller.
Ummm,
Could you clarify something...are you thinking something like Perl's (25th birthday today) (camel book by Larry Wall, p44) handles or a Bash HERE document ?
Update (based on discussion below): This will integrate python files and other externalities into a single installable:
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/Manual.html?format=raw#create-a-spec-file-for-your-project
http://www.pyinstaller.org/export/d3398dd79b68901ae1edd761f3fe0f4ff19cfb1a/project/doc/images/SE_exe.png