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..
Related
i have a project about sorting data from files. However when i tried to implement main.cpp, i got an error.
TERMINAL OUTPUT:
Executing task: /usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main.cpp -o /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main
Undefined symbols for architecture arm64:
"TestBed::setAlgorithm(int, int)", referenced from:
_main in main-f84827.o
"TestBed::execute()", referenced from:
_main in main-f84827.o
"TestBed::TestBed()", referenced from:
_main in main-f84827.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process "/bin/zsh '-c', '/usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main.cpp -o /Users/utku/Desktop/workspaces/cppworkspace/homework-1/main'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
(Using VSCode and M1 MacBook) ,
¨
using namespace std;
int main(int argc, char *argv[]) {
string testfile;
if (argc < 2) {
cout << "Enter a test file name:" << endl;
cin >> testfile;
}
else {
testfile = argv[1];
}
ifstream file(testfile.c_str());
if (file.is_open()) {
cin.rdbuf(file.rdbuf());
}
else {
cout << "Error: cannot read the test file!" << endl;
return -1;
}
int algorithmType = 0;
int k = 0;
// Numbers are obtained from the file line by line with cin
cin >> algorithmType;
cin >> k;
// Create a TestBed object, initialize and execute the algorithm
TestBed *test = new TestBed() ;
test->setAlgorithm(algorithmType,k);
test->execute();
return 0;
}¨
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
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;
}
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?
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.