g++ problem with -l option and PostgreSQL - postgresql

I've written simple program.
Here a code:
#include <iostream>
#include <stdio.h>
#include <D:\Program Files\PostgreSQL\8.4\include\libpq-fe.h>
#include <string>
using namespace std;
int main()
{
PGconn *conn;
PGresult *res;
int rec_count;
int row;
int col;
cout << "ble ble: " << 8 << endl;
conn = PQconnectdb("dbname=db_pm host=localhost user=postgres password=postgres");
if (PQstatus(conn) == CONNECTION_BAD) {
puts("We were unable to connect to the database");
exit(0);
}
}
I'm trying to connect with PostgreSQL.
I compile this code with following command:
gcc -I/"d:\Program Files\PostgreSQL\" -L/"d:\Program Files\PostgreSQL\8.4\lib\" -lpq -o firstcpp.o firstcpp.cpp
This command is from following site:
http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
And when I compile it I get following error:
/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open -lpq: No such file or directory
collect2: ld returned 1 exit status
Does anyone help me?
Difek

You can try using forward slashes instead of backward slashes. And I have no idea about the first forward slash. Isn't it meant to be inside the quotes ? Eg -I"/d:/Program Files/PostgreSQL/"
Anyway, if you are using the gcc from cygwin, you could also try
-I"/cygdrive/d/Program Files/PostgreSQL"
And I'd do the same with that include (libpq-fe) - though apparently that is working, the error is in the linker.

Related

why code runner can't run cgo program in vscode?

It;s my test code.
package main
/*
#cgo LDFLAGS: -ldl
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
static void SayHello(const char* s) {
puts(s);
}
*/
// void SayHello2(const char* s);
import "C"
func main() {
C.SayHello(C.CString("Hello, World\n"))
C.SayHello2(C.CString("Hello, World123\n"))
}
#include <stdio.h>
void SayHello2(const char *s) {
puts(s);
}
when i try the right click, it's not work, and catch some err:
/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
Undefined symbols for architecture arm64:
"_SayHello2", referenced from:
__cgo_a234d07dd13f_Cfunc_SayHello2 in 000001.o
(maybe you meant: __cgo_a234d07dd13f_Cfunc_SayHello2)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
but when i use vscode run and debug, everything is ok,
Starting: /Users/pandy/go/bin/dlv dap --check-go-version=false --listen=127.0.0.1:64352 --log-dest=3 from /Users/pandy/GolandProjects/CGO/pkg03
DAP server listening at: 127.0.0.1:64352
Type 'dlv help' for list of commands.
Hello, World
Hello, World123
Process 4948 has exited with status 0
Detaching
dlv dap (4910) exited with code: 0
is there some tips when use code runner?
i want to know why..

error in compiling my first code in C++ in VS code editor through mingW

I have authored the following Hello World C++ example...
#include <iostream>
using namespace std;
int main(){
cout << "Hello World!";
return 0;
}
...however, I am getting the following error message.
"e:\reality\visual studio\" && g++ first.cpp -o first && "
e:\reality\visual studio\"first
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):
(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status

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;
}

Including edk2-libc in efi shell application

How would one approach adding support for https://github.com/tianocore/edk2-libc, say I want to include stdio and use printf in my edk2 application? I followed StdLib/Readme.txt, and am able to successfully build examples in the AppPkg, however, when I try to add StdLib to my project I get errors like these:
LibString.lib(Searching.obj) : error LNK2005: strspn already defined in LibString.lib(Searching.obj)
LibCtype.lib(CClass.obj) : error LNK2005: isspace already defined in LibCtype.lib(CClass.obj)
(...)
LibC.lib(Main.obj) : error LNK2001: unresolved external symbol main
I do have the boilerplate (!include StdLib/StdLib.inc) added to my dsc file and in inf, I have StdLib.dec added to Packages and LibC and LibStdio added to LibraryClasses. I am using VS2017 toolchain for compilation and am using edk2-stable202108 release.
I was able to achieve this using below configuration for Hello Application of AppPkg.
Hello.inf
[Defines]
INF_VERSION = 0x00010006
BASE_NAME = Hello
FILE_GUID = a912f198-7f0e-4803-b908-b757b806ec83
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 0.1
ENTRY_POINT = ShellCEntryLib
#
# VALID_ARCHITECTURES = IA32 X64
#
[Sources]
Hello.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
StdLib/StdLib.dec
[LibraryClasses]
UefiLib
ShellCEntryLib
BaseLib
BaseMemoryLib
MemoryAllocationLib
LibStdLib
LibStdio
LibString
DevConsole
Hello.c
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/ShellCEntryLib.h>
#include <stdio.h>
int
main (
IN int Argc,
IN char **Argv
)
{
printf("Hello, world!\n");
return 0;
}
What I have understood is that LibC has ShellAppMain() defined in it which internally calls extern main(). So You need to provide definition of main() in your source just like I did in Hello.c

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?