I am using the '/FC' option in VisualStudio 2010 to get the full path file name from the FILE macro, but the file name is getting traced in lower case.
It is documented in below link:
https://msdn.microsoft.com/en-in/library/027c4t2s(v=vs.100).aspx
Is this a expected behaviour or any change in the Project properties can give the FileName correctly instead of filename in total lower case?
Example:
I have the below code in Visual Studio 2010
#include "stdafx.h"
#include <iostream>
using namespace std;
void logEvent(const char* const fileName)
{
cout << "Full path file name:" << fileName << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
logEvent(__FILE__);
getchar();
return 0;
}
The above code is coded in file name: FileNameTest.cpp
But the output for the above is shown as:
Full path file name:c:\users\pradp\documents\visual studio
2010\projects\filenam etest\filenametest\filenametest.cpp
AS you can see the total filename is traced in lower case
The setting made in the VisualStudio :
Project -> Properties -> C/C++ -> Advanced -> UseFullPaths
Related
As you know, "Windows Terminal" application is exist in Windows 11.
Here is a screenshot from that application:
And here my source codes of my C++ program:
#include <clipboardxx.hpp>
#include <iostream>
#include <string_operations.h>
using namespace clipboardxx;
using namespace std;
///--- Değişkenler ---///
//clipboard
clipboard clpPano;
//string
string strOgeninKonumu;
int main(int argc, char* argv[])
{
if(argc == 2)
{
strOgeninKonumu = string(argv[1]);
ReplaceString(strOgeninKonumu, "\\", "\\\\", 0, strOgeninKonumu);
strOgeninKonumu = "\"" + strOgeninKonumu + "\"";
clpPano << strOgeninKonumu;
}
return 0;
}
I use Code::Blocks as IDE.
I set the application type to "GUI application" in order to create hidden console application.
If I choose "Windows Console Host" option, my program does not flash.
But if I choose "Windows Terminal" option, my program flashes.
How do I create %100 hidden C++ program and prevent flashing in Code::Blocks?
I have this program
#include <stdio.h>
#include <mpi.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int size;
int rank;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("Hello, World!");
cout << MPI_Comm_rank << " " << MPI_Comm_size << endl;
MPI_Finalize();
return 0;
}
When I debug this in Microsoft Visual Studios it works just fine. But when I try it in the command prompt or any terminal I get this error,
Project_1.cpp:2:10: fatal error: mpi.h: No such file or directory
2 | #include <mpi.h>
| ^~~~~~~
compilation terminated.
I have g++ installed already and it works with other programs just fine. I have MPI installed too. Was able to link it to my Microsoft Visual Studio but it only works in its debug section. I am using a windows computer. Not really sure what to do. Any help would be great thanks.
There are some problem with your program:
You don't define MPI_Comm_rank and MPI_Comm_size but you try to print them in cout. In the following piece of code, I've rewritten your code.
#include <stdio.h>
#include <mpi.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int size;
int rank;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("Hello, World!");
cout << rank << " " << size << endl;
MPI_Finalize();
return 0;
}
You also need to add the location of mpiexec.exe to your system PATH by :
1- Open Window’s System Properties dialog box => click on Environment Variables
2- Click edit for the Path variable => add C: Program Files\Microsoft MPI\Bin \ (Assuming the default install)
To include the appropriate libraries.
1- The MPI code should be compiled as a Console Application
2- Once you have created the project you need to add the appropriate library
Right-click on the project in the Solution Explorer and go to Properties
Click on VC++ Directories and (assuming the MPI SDK is installed in the default directory) add:
C:/ Program Files (x86)/Microsoft SDKs/Include to the Include Directories
C:/Program Files (x86)/Microsoft SDKs/Lib/x64 or C:/Program Files (x86)/Microsoft SDKs/Lib/x86 to the Library Directories
Depends on whether you wish to compile your code as 32bit or 64bit
3- Click on Linker =>Input
Under Additional Dependencies add msmpi.lib
// End Of Line.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <fstream>
#include <streambuf>
#include <cstdio>
using namespace std;
ifstream input_file;
int EOL = 0;
int main()
{
//Enter end of line data into file
input_file.open("EOL Data", ios::in);
do
{
cout << "\n" << "\n" << "\n" << "\n";
++EOL;
} while (EOL == 0);
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add
existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln
file
When trying to execute the above, get the error" Not enough resources to execute the program". Not
sure why this error is being posted.
Found the problem, opening the file is input, should have been opened as output. Not sure why this would generate a resource limitation problem.
I looked at numerous posts concerning this problem but none of them apply in my case.
I have a C++ class in one file that has 3 methods. I can set a breakpoint in one method. However, I cannot set a breakpoint on any line of code in the other two methods. This class is build as a library with DEBUG set. All optimizations are turned off.
Below is the code for the two problem methods in this class.
Blockquote
#include "pch.h"
#include <stdio.h>
#include <afxwin.h>
#include <cstring>
#include <io.h>
#include <iostream>
#include <string>
#include "Log.h"
CLog::CLog()
{
ptLog = NULL; // this is the file ptr
}
void CLog::Init()
{
int iFD;
DWORD iLength;
int iStat;
HMODULE hMod;
std::string sPath;
std::string sFile;
int i;
hMod = GetModuleHandle(NULL); // handle to this execuatble
std::cout << "Module = " << hMod;
if(hMod)
{
// Use two bytes ASCII (UNICODE) if set by compiler
char acFile[120];
// Full path name of exe file
GetModuleFileName(hMod, acFile, sizeof(acFile));
std::cout << "File Name = " << acFile<<"\n";
// extract file name from full path and append .log
sPath = acFile;
i = sPath.find_last_of("\\/");
sFile = sPath.substr(i + 1);
sFile.copy(acFile, 120);
std::cout << " File Name Trunc = " << sFile;
sFile.append(".log");
iStat = fopen_s(&ptLog, sFile.data(), "a+"); // append log data to file
std::cout << "fopen stat = " << iStat;
if (iStat != 0) // failed to open error log
{
return;
}
iFD = _fileno(ptLog);
iLength = _filelength(iFD);
// Check length. If too large rename and create new file.
if (iLength > MAX_LOG_SIZE)
{
fclose(ptLog);
char acBakFile[80];
strcpy_s(acBakFile, 80, acFile);
strcat_s(acBakFile, ".bak"); // new name of old log file
remove(acBakFile); // remove previous bak file if it exists
rename(acFile, acBakFile);
fopen_s(&ptLog, acFile, "a+"); // Create new log file
}
}// end if (hMod)
}
,,,
ptLog is declared as FILE *
This class is invoked with the following code:
#include <iostream>
#include "..\Log\Log.h"
int main()
{
CLog Logger;
Logger.Init();
Logger.vLog((char *) "Hello \n");
}
Blockquote
This code is also compiled as debug. If a set a breakpoint on "Loggger.Init()"
the debugger will hit the breakpoint. If select 'Step Into' it will not enter
the code in the Init() method. The code does execute since I can see the text on the console. If I put breakpoints anywhere in the Init() method they do not break.
I did the following:
Removed log.lib from the input to the Linker.
Obviously, the Link failed due to unresolved externals.
Put back log.lib and rebuilt.
Turned off the option "Require source files that exactly match the original version"
Debug and breakpoints worked.
Enabled the option.
Retried debug and the breakpoints still worked.
Did a full rebuild and breakpoints worked.
I don't really understand it because I had performed numerous cleans and rebuilds
previously.
I did find another issue. I had '/clr' option on.
This is for Common Language Runtime support for the .lib.
The module linked to it did not have Common Language Runtime on. In this case,
the breakpoints were ignored. When I turned off '/ clr', the breakpoints
functioned properly
This is the code I have for checking if a file exists in my visual studio 2010 c++ project:
bool GLSLProgram::fileExists( const string & fileName )
{
struct stat info;
int ret = -1;
ret = stat(fileName.c_str(), &info);
return 0 == ret;
}
I am not sure why it returns false for "shaders/color.vert" when that file really exists, and shaders is a folder in my project main folder.
Can you see something wrong?
THanks
Ok, so to illustrate the quirks of running from the IDE here's a little test I did. Hopefully this should help you figure out how relative paths work in VS.
So my folder hierarchy looks like this:
/_Sandbox
_Sandbox.sln
/Debug
_Sandbox.exe
/shaders
color.vert
/_Sandbox
_Sandbox.proj
main.cpp
The code looks as follows:
#include <iostream>
#include <string>
#include <sys/stat.h>
int main(int argc, char* argv[])
{
struct stat info;
std::string path = "shaders/color.vert"; // To not I get the same behavior with "shaders\\color.vert"
int ret = stat(path.c_str(), &info);
ret == 0 ? std::cout << "File found." << std::endl : std::cout << "File doesn't exist." << std::endl;
std::cin.get();
return 0;
}
So if I run this in the IDE, I get "File doesn't exist.", if I run this outside the IDE, I get "File Found". In order for the program to find the shader file from inside VS I have to put the shader folder like so:
/_Sandbox
_Sandbox.sln
/Debug
_Sandbox.exe
/_Sandbox
/shaders
color.vert
_Sandbox.proj
main.cpp
You can however get the code to find the folder from inside and outside the IDE. What you have to do is go to your project's settings. In "Debugging" and change "Working directory" to $(SolutionDir)$(Configuration)\
Hopefully this clears things up for you.