Why do I get "Failed to open macho file..." when running program under VSCODE but not under normal shell? - visual-studio-code

I have a C++ program (compiled using CLANG++) that executes CLANG++ to compile another program. When I run this program using OSX shell it runs fine. When I run it under VSCODE debug it runs but following message is displayed: "023-01-12 15:01:02.577820-0800 clang++[10766:1004764] Failed to open macho file at /Library/Developer/CommandLineTools/usr/bin/clang++ for reading: Too many levels of symbolic links". I'm assuming that this message is coming from CLANG++ but I couldn't swear to that. Note, too, that the return code from clang++ is 0.
The routine that executes the compiler is (Note that I also have a routine that runs the compiled program but there isn't any problem with that):
void compileit(){
string codeLoc = "/usr/bin/clang++";
vector<char *> argv;
argv.push_back((char *)codeLoc.c_str());
argv.push_back((char *)"-g");
argv.push_back((char *)"-std=c++14");
argv.push_back((char *)"-otest.a");
argv.push_back((char *)"test.cpp");
argv.push_back((char *)NULL);
pid_t pid;
if ((pid = fork()) < 0) {
cout << "Fork failed" << endl;
exit(999);
}else if (pid > 0) {
cout << "Launching compiler" << endl;
int wstatus;
waitpid(-1, &wstatus, 0);
if (wstatus == 0){
cout << "CPP compiled successfully" << endl;
return;
}else{
cout << "Compile of CPP file failed: " << wstatus << endl;
}
}else{
int status = execv(codeLoc.c_str(),&argv[0]);
cout << "Couldn't launch the compiler" << endl;
exit(998);
}
}
type here
The program being compiled (by the code above) is:
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "\nhello world" << endl;
return 0;
}
type here
The launch.json file is:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: clang++ build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": ["-b1"],
"cwd": "${workspaceFolder}",
"preLaunchTask": "C/C++: clang++ build active file",
}
]
}
And, the output displayed by VSCODE's terminal when I run the program (including the output when it is run) is:
Launching compiler
2023-01-12 15:01:02.577820-0800 clang++[10766:1004764] Failed to open macho file at /Library/Developer/CommandLineTools/usr/bin/clang++ for reading: Too many levels of symbolic links
CPP compiled successfully
From main: Launching test.a
test.a completed successfully
From forked main: Launching test.a
carl#McTreehouse test %
hello world
type here
A caveat: I'm new to Stack Overflow so If I've not provided enough or the correct information please let me know and I'll provide updates. I'm also more of a hobbyist c++ programmer than a professional (my background is Tandem/HP Nonstop TAL/Cobol).
My original code, which was related to a larger project, exhibited this behavior so I tried to reduce the specifics to the code described above. I had hoped that something I was doing in the larger context was causing the problem but after getting the specific code to its minimal state the problem persisted.
I spent some time looking at the VSCODE properties but couldn't spot anything that seemed like a problem. I also went looking for symlinks in the /Library/Developer directory but didn't spot anything (but could have easily missed it).
What I'm concerned about it this behavior showing up randomly when running the larger project from the shell or as a CGI.

Related

Visual Studio Code cant run c++ after resetting windows

I need help.
I installed Visual Studio Code, then I installed the latest version of MingW for C++ programming.
When I try to run the program, show this
[Running] cd "d:\projects\helloword" && g++ helloword.cpp -o helloword && "d:\projects\helloword"helloword
'g++' �����ڲ����ⲿ���Ҳ���ǿ����еij���
���������ļ���
[Done] exited with code=1 in 0.042 seconds
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
return 0;
}

trying to connect to pgsql in qt driver not loaded

I have windows 10, qt version is 4.14.1 postgres version is 13.3 (most recent as of 7/23/21. When I run the following code below in qt it gives me the following error.
"Driver not loaded Driver not loaded"
("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
I have tried to place dll files into areas like the person in the following youtube video https://www.youtube.com/watch?v=qeErME39zvw as this worked when I was trying to set up MySQL on qt
QSqlDatabase db2 = QSqlDatabase::addDatabase("QPSQL");
db2.setHostName("127.0.0.1");
db2.setUserName("test");
db2.setPassword("test");
db2.setDatabaseName("test");
if (db2.open())
{
qDebug() << "\n\n\n database connected successfully\n\n\n";
}
else
{
qDebug() << "\n\n\n database connection go poop \n\n" << db2.lastError().text() << " \n ";
qDebug() << QSqlDatabase::drivers();
}
qDebug() << QSqlDatabase::drivers();
db2.close();
return 0;

While handling interrupt signal in 'http_listener.h' gives segmentation fault using Microsoft CppRestSdk

I am using 'https://github.com/microsoft/cpprestsdk' v2.8 and trying to handle interrupt signal but 'cpprest/http_listener.h' gives segmentation fault.
If I comment out line no 3( #include <cpprest/http_listener.h>) server gets stop without any segmentation fault.
My code snippet is as below
#include <iostream>
#include <cpprest/http_listener.h>
void signal_handler(int signal) {
std::wcout<<"Exiting the program... ::" << signal << std::endl;
exit(EXIT_SUCCESS);
}
int main(int argc, char** argv) {
//Registring a signal handler to prevent abrupt exits
std::signal(SIGINT, signal_handler);
try {
while (true);
}
catch (std::exception const & e) {
std::wcout << e.what() << std::endl;
}
return 0;
}
Versions used :
OS - Linux 16.04
CPP REST version - 2.8
G++ version - 7.5.0
Command to compile above code snippet - g++ test.cpp -o spike_op1 -lcpprest -lssl -lcrypto -lpthread
So there is issue in cpprest/http_listener.h file, does anyone have it's solution?

Visual Studio Code's intellisense doesn't recognize Arduino port managing

I'm trying to use VScode for Arduino Uno early development. I'd like to use intellisense but in the "Problems tab" it shows me errors:
identifier "DDRD" is undefined
identifier "PIND" is undefined
identifier "PORTD" is undefined
identifier "PORTD" is undefined
I can compile and upload the code flawlessly and it works.
I read everywhere that the solution to this is adding at the very top of the code the macro definition of the microcontroller, but it seems that this doesn't work for me only.
This is my code
#define __AVR_ATmega328P__
#include <avr/io.h>
#include <util/delay.h>
int main(void) {
int switchState = 0;
DDRD &= ~(1 << 2);
DDRD |= 1 << 3;
DDRD |= 1 << 4;
DDRD |= 1 << 5;
for (;;) {
switchState = 0x01 & (PIND >> 2);
if (!switchState) {
PORTD |= 1 << 3;
PORTD &= ~(1 << 4);
PORTD &= ~(1 << 5);
} else {
PORTD &= ~(1 << 3);
PORTD &= ~(1 << 4);
PORTD |= 1 << 5;
_delay_ms(250);
PORTD |= 1 << 4;
PORTD &= ~(1 << 5);
_delay_ms(250);
}
}
return 0;
}
If I right-click a DDRD underlined macro and select "Go to definition" it brings me to the DDRD macro definition in io76c711.h, while I expect been redirected in iom328p.h, because io.h contains
#elif defined (__AVR_ATmega328P__)
# include <avr/iom328p.h>
It seems that AVR_AT76C711 is defined somewhere else but I can't wonder where.
Do you have any suggestion? I also post my c_cpp_properties.json if there is something wrong in the one generated by the VScode Arduino extension
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\Program Files (x86)\\Arduino\\tools\\**",
"D:\\Arduino\\libraries\\**",
"C:\\Program Files (x86)\\Arduino\\libraries\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\tools\\**",
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**"
],
"forcedInclude": [
"C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
],
"defines": [
"USBCON"
],
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14"
}
],
"version": 4
}
Add "__AVR_ATmega328P__" to the define section of your c_cpp_properties.json file as follows:
"defines": [
"__AVR_ATmega328P__",
Then it will be able to find the correct AVR IO include file.
In your case, AVR_AT76C711 was just one possibility for the definition, but it likely wasn't actually defined in your project.
Note: the define will automatically be removed the next time that the IntelliSense Configuration is rebuilt (e.g.: Verify or Upload). This issue is currently tracked here.
The issue is that the header files with register definitions/initializations such as <avr/iom328p.h> are only included at compile-time by the compiler. As a result, intellisense has no clue about those definitions while error-checking your code. By manually defining which board you use or by setting a compiler argument (which would normally be set at compile-time), you can get intellisense to recognize the necessary header files.
Adding the flag "-mmcu=atmega328" to my Arduino configuration's compilerArgs (within c_cpp_properties.json) resolved this intellisense issue. Obviously change the atmega chip number as needed.
"configurations": [
{
"name": "Arduino",
"compilerPath":
"path\\to\\your\\compiler",
"compilerArgs": [
"-mmcu=atmega328"
],
"intelliSenseMode": "gcc-x64",
"includePath": [
"paths\\to\\include"
]
}
]
If this change keeps getting cleared, it will be necessary to disable the auto-generation of the c_cpp_properties.json file. This setting ID is : arduino.disableIntelliSenseAutoGen

d aGetting error while connecting to Postgres via dev c++

I am trying to get connected to Postgres database via Dev-c++ (Windows application and not console) for executing queries, but I am continuously getting errors.
I went through the following link:
http://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm
and added the below code to that of mine:
#include <iostream>
#include <pqxx/pqxx>
using namespace std;
using namespace pqxx;
int main(int argc, char* argv[])
{
try{
connection C("dbname=testdb user=postgres password=cohondob \
hostaddr=127.0.0.1 port=5432");
if (C.is_open()) {
cout << "Opened database successfully: " << C.dbname() << endl;
} else {
cout << "Can't open database" << endl;
return 1;
}
C.disconnect ();
}catch (const std::exception &e){
cerr << e.what() << std::endl;
return 1;
}
}
But got error stating:
'No such file or directory
#include
Compilation terminated'
Please, Can anyone help me get through this?
is there any other possible way to get connected?