c++: compile with library argument in xcode [duplicate] - c++

This question already has answers here:
xcode library not found
(14 answers)
Adding Linker Flags in Xcode
(3 answers)
Closed 8 years ago.
In terminal, this works:
g++ -lgmp main.cpp
while this does not:
g++ main.cpp
I am using X-code as my IDE and how could I tell X-code to add the statement '-lgmp' when compiling? Thank you:)
Edit: I did according to the article providing the answer:
but I still fail:
and this is the error message:
More information:
I have to use c++98 instead of c++11 because one of my package Gurobi requires that. Do you know any solution? thank you:)

Related

C++ program will not compile when called from command line, but works in Eclipse [duplicate]

This question already has answers here:
Error "undefined reference to 'std::cout'"
(6 answers)
What is the difference between g++ and gcc?
(10 answers)
Closed 1 year ago.
I'm doing a basic Hello World script, and anytime I try to compile it from the command line (example gcc -o hello.o hello.cpp) I get a massive cascade of errors before being informed that the linker exited with an error. However, when I build the file via the Eclipse C++ IDE, it works fine. I'm on MacOS 11.3.1. Checking the version of the compiler with gcc -v gives me
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I've verified that if I simply put a main function that returns a value it will compile, so the issue is somewhere with the std::cout << "Hello world"; line. I have some experience with other languages, but this is my first attempt at anything with C++.

Filesystems undefined reference [duplicate]

This question already has answers here:
how to use std::filesystem on gcc 8?
(3 answers)
'std::filesystem' has not been declared after including <experimental/filesystem>
(3 answers)
Closed 1 year ago.
I having problem with filesystems library. I have seen many solutions from SO and multiple other forums, but none of them works for me. (I will add list most of them bellow)
System specs:
WSL - Ubuntu 18.04 on Windows 10 build 19041
G++:
g++-8 (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0
Linker error:
the message is prety chaotic so I will show just the important parts of error message and the complete error message will be bellow.
undefined reference `std::experimental::filesystem::v1::file_size(...)
undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()
From what I see the header file is here, but the source file with definitons is not included.
I have tried:
Adding -lstdc++fs along with -std=c++17
Using both #include <filesystems> and #include <experimental/filesystems> - in first case it doesn't even see the header file of the lib. I even tried some other -std=... flags that I can't name right now.
The complete error: https://pastebin.com/HuePgrMw

g++ 'stod' was not declared in this scope [duplicate]

This question already has answers here:
cygwin g++ std::stoi "error: ‘stoi’ is not a member of ‘std
(5 answers)
Closed 6 years ago.
I am trying to compile the following code using g++ (version 4.8.1) in cygwin, and it seems that it cannot use the function stod():
//test.cpp
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
string a="1.23";
cout<<stod(a);
return 0;
}
I keep getting this eroor:
test.cpp:9:14: error: 'stod' was not declared in this scope
cout<<stod(a);
I read another thread that has the same problem. There, people suggested to use c++11 to address it. So I tried both the following commands to compile it but still got the same error:
g++ -std=c++0x test.cpp -o test
g++ -std=c++11 test.cpp -o test
Does anyone know a solution to this problem?
And how do I know that c++11 is enabled? Do I need to modify my code in order to use it?
Thanks a lot!
It works in GCC 4.8 on Coliru (http://coliru.stacked-crooked.com/a/8a68ad0ca64c1bff) and also in Clang on my machine. It could be that somehow your Cygwin system doesn't support this function. I suggest you work around it by simply using good old strtod() instead. That's probably what stod() uses under the hood anyway.

Will -std=c++11 compiler flag be default at some point? [duplicate]

This question already has answers here:
Why C++11 compiler support still requires a flag?
(2 answers)
Closed 8 years ago.
As in title. Will it be default or to use C++11 features we will always have to add -std=c++11?
Right now, because of this option, C++11 still feels like some extra, non-standard thing.
To specify compiler, -std=c++11 flag is used by clang, g++ and even ICC.
With g++, use -dumpspecs to generate a specs file.
Use -print-search-dirs and first line is where to place specs file.
Add the -std=c++11 option appropriate place in specs file, on the line following *cc1plus:.

How to reproduce #include_next compile time error? [duplicate]

This question already has answers here:
Error compiling OpenCV, fatal error: stdlib.h: No such file or directory
(5 answers)
Closed 2 years ago.
I have a library that could be compile on windows, And now i need to compile on WSL (Debian 9.5). But i get a confusing compile error:
/usr/include/c++/6/cstdlib:74:15
#include_next <stdlib.h>
No such file or directory.
I try to change INCLUDEPATH variable (which i use QMake) but that make no sens. And i couldn't reproduce this error message on another project. How this could be happened ? and how could fix it ?
Specification:
- OS: Debian 9.5 on WSL (Windows 10)
- Compiler: GCC 6.3.0
- C++ Standard: C++17
- Include Paths: /usr/include | /usr/local/include | /usr/include/c++/6/
I think the answer is on another answer here.
Which is to disable precompiled headers.
-DENABLE_PRECOMPILED_HEADERS=OFF