|
Thank you, your answer is clear. Now the point is that I am not used at all in c++ compiling/linking and I am not used to VS configuration of compiler and linker, so I ask if you could help. Correct me if I am wrong : (we are within VS2019)
1) a create a new cc++ emty project
2) Add main.cpp , header.cpp and header.h to the project.
3) Include header.h in main.cpp
Now from the VS2019 environment, how do I compile separately main.cpp and header.cpp? I guess I have to compile header.cpp before. Isn't it? But how do I do that?
And then, how do I compile main.cpp and how the VS2019 knows, while compiling main.cpp, where to get the method implementation i.e. the header.obj?
|
|
|
|
|
If you've created a VS C++ project, it knows how to deal with files that you add to the project. All you should need to do for a simple project is hit Build, and the IDE will take care of the rest.
Keep Calm and Carry On
|
|
|
|
|
Ok I tried and I did it. I right clicked on header.cpp and it gave the option to compile. This created the header.obj. Then I right clicked on the main.cpp and again I had the option to compile it and this generated the exe. Before doing all this I included in the main.cpp only header.h,
Now it works. Thanks for the clear explanation
|
|
|
|
|
|
|
Roberto64_Ge wrote: main.cpp includes header.cpp which includes header.h This means that all the definitions in header.cpp will be duplicated in the object files. Do not include .cpp files in others, only include the actual headers, i.e. in this case main.cpp should only include header.h.
|
|
|
|
|
|
I there a way to track down the linker errors further than what`s being offered in the "Build output" window?
|
|
|
|
|
Not really. You can increase number of linker messages by changing the "Show Progress" option. The "Display all messages" is really verbose.
Otherwise, sometimes they can be tricky to trace. Just yesterday I had one where an include directive was used after a
namespace blah_blah { line. Linker was looking for a function definition inside the namespace when it was actually outside.
Mircea
|
|
|
|
|
If you actually provide some details then maybe we can help.
|
|
|
|
|
I`m not sure what details you are expecting. All I have in the build output window is a one line message:
1>Tutorial07.obj : error LNK2001: unresolved external symbol "void __cdecl CheckCollisions(class std::vector<class gameelement="" *,class="" std::allocator<class="" *=""> > *,int,class contim *,int)"
I know an error of this type means that some parameters don`t match in the function definition, declaration and the place where the function is being used. I did a search for the function name within the code file, everything seems to be fine in the function header (return type, function name and parameters) everywhere. I need more details to know what exactly doesn`t match.
void CheckCollisions(vector<gameelement * > * GAllElements, int UnitCount, contim* OldNewTable,int frame);
never mind I found the error, it was a parameter mismatch, you have to be extra careful with those.
modified 27-Aug-22 15:51pm.
|
|
|
|
|
I have a json file genrated in python from another system that needs to be read/updated in another MFC application. I can successfully read the existing data from the json file using nlohmann json add-in. For example, the file consists of two data fields with one field having any array of two subfields as below
{
"city_data":[
{
"t":"m",
"l":[12.0,10.3,0.0,1.0]
},
{
"t":"l",
"l":[10.1,20.37,0.0,1.0]
},
{
"t":"l",
"l":[47.82,4.63,0.0,1.0]
},
{
"t":"m",
"l":[67.66,43.33,0.0,1.0]
}
],
"map_data":"JZDKZTCaTyWQymUwmk8lkMplMJpPJZDKZTCaTyWQymUwmk/8/+n8AVAZ1WCxk8rYAAAAASUVORK5CYII="
}
The "map_data" is basically base64 encoded png image.
I would like to add more entries into "city_data" field as {"t":"x","l":[0.0,0.0,0.0,0.0]} while the "map_data" stays the same. Then I can write the json object into a new file with updates.
To read the json file,
std::ifstream f(file);
json data = json::parse(f);
To retreive "city_data" and then its type and location
json& cityInfo = data["city_data"];
for (unsigned int i = 0; i < cityInfo.size(); i++)
{
json& cityType = cityInfo[i];
std::string ctyTyp = cityType["t"];
json& cityLoc = cityType["l"];
std::float_t x = cityLoc[0];
std::float_t y = cityLoc[1];
}
ofstream outfile;
outfile.open(m_strFolderPath + m_strFileName + ".png", ofstream::binary);
std::string mapFrame = data["map_data"];
string temp = base64_decode(mapFrame );
outfile.write(temp.c_str(), temp.size());
outfile.close();
f.close();
Any suggestions on how to insert new city_data fields into the nlohmann JSON object? or a way to create a new json file like in above format?
thanks
PKNT
modified 26-Aug-22 14:17pm.
|
|
|
|
|
I haven't used nlohmann json in a while (because I've made my own - see mlib/json.h at master · neacsum/mlib · GitHub[^]
However I think this should work:
cityInfo[i]["newval"] = to_string (i + 1);
--EDIT--
I read your message again and realized you want to extend the cityInfo array. In this case you would simply write something like:
cityInfo[4] = json::parse(R"({"t":"x", "l" : [0.0, 0.0, 0.0, 0.0] })");
Mircea
modified 26-Aug-22 21:09pm.
|
|
|
|
|
Hi
I have some question about the class. I would like to use it on My CRichEditctrl where the source code is for my debugger.
There are CWnd members in a number of the methods in the class would that in my case be the CrichEditCtrl in Addition the HiTest api which has a CPoint member is that point relative to (in my case) the CRichEditCtrl
Thanks
|
|
|
|
|
Umm, could you formulate your question(s) a bit more clear?
|
|
|
|
|
I’ll ask a more specific question the create api of the CtooltipCtrl class has 2 parameters CWnd and dwstyle
I would like to use it in my derived CrichEditctrl class whose parent is a CDialog should the Cwnd be the CRichEditrl or The CDialog
Thanks
|
|
|
|
|
It depends upon what and how are you going to display tooltips for your control.
If it would be some text for the whole control then pass the CDialog CWnd* (in this case you will handle the TTN_NEEDTEXT notification in the dialog class).
If the tooltip text would depend on some position or some content within the controls then it could be better passing the control CWnd* (then you will handle the TTN_NEEDTEXT notification in the control's class).
|
|
|
|
|
Maybe its best if I used as an example if I have the following text in my CrichEditctrl
D203 B11A 801C 0011A 0001C MVC FIELDA,FILEDB
and I however the mouse over FIELDB which has a value of X'00000003' I would like the tool tip control to display it much like the visual studio debugger
Hope this makes sense
thanks
|
|
|
|
|
Then you should create the tooltip control within your CrichEditctrl class passing the CrichEditctrl CWnd* as the parent.
Then you would have to implement some handling (the mouse move - ?) procedure to determine what text is to be displayed in tooltip. If the will be some (new!) text then use the following CToolTipCtrlmethods:
UpdateTipText
TrackPosition
TrackActivate
|
|
|
|
|
|
|
Using VS2019 (/std:c++20) and VS2022
I'm trying to formally document some code in header files.
Most of the time, adding comments does not seem to work properly in Intellisense.
What is the proper C++ comment format ?
This is mostly used to generate offline documentation (as far as I can see) and does not plays well with intellisense.
Seems sometimes intellisense breaks down and does not fully display or does not format the comments in the info tooltips.
For example :
sometimes this works or not:
struct ApplicationArguments {};
sometimes this works or not :
struct ApplicationArguments {};
I'm kind of baffled.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
That is the format I use and it seems to work fine. However, I have noticed with some of the system functions that a double slash works as well.
|
|
|
|
|
elephant me.
First, don't tell me to upgrade, for this project I'm stuck on VS2008 for an embedded project. From time to time, I need to move a development project to new hardware. Lets say I start on LAPA (laptop A) and I copy it to LAPB. When I open the project (we'll call it Fred and my user name is chg) on LAPB, I now have to user project files in the folder:
- Fred.vcproj
- Fred.vcprog.LAPA.chg.user
- Fred.vcprog.LAPB.chg.user
Now I can see VS loading fred.vcproj and then adding a specific user's settings - sort of - but I cannot come up with a good reason why the machine name would be included. In any event, on LAPB, I would expect to pick up those settings. Instead, I find that some of my project settings have changed:
- Deployment changes from the old setting to %CSIDL_PROGRAM_FILES%\fred.exe
- Debugging remote executable changes from the default to %CSIDL_PROGRAM_FILES%\fred\fred.exe
for ALL targets.
This would be a minor irritation if we were just talking about my example, but my actual application has over 80.
Comparing the user vcproj files, I see where the RemoteMachine has changed as well as the RemoteExecutable. But if I update these in the new LAPB project file, I still get %CSIDL_PROGRAM_FILES% inserted.
Any insight before I start slogging through this crap?
some of my deployment settings default to whatever MS deems appropriate.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
modified 21-Aug-22 14:59pm.
|
|
|
|
|
With the disclaimer that I couldn't possibly try my suggestion on VC2008 (got rid of it long time ago) here is how I handle a similar issue.
- Keep everything under Git source control
- Add *.user to .gitignore
- Have everything setup once the way you like it on LAPA and LAPB.
Now every time you want to transfer from LAPA to LAPB you do git push on LAPA and git pull on LAPB. That keeps all *.user files the way you set them.
Mircea
|
|
|
|