Filesystems undefined reference [duplicate] - c++

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

Related

If MinGW-w64 doesn't support wWinMain, then what C++ compiler should I use instead? [duplicate]

This question already has answers here:
undefined reference to `WinMain#16'
(7 answers)
wWinmain, Unicode, and Mingw
(3 answers)
Closed 9 months ago.
I've been attempting to follow this guide here for writing a program in C++ that allows me to create an application window, however I ran into an issue where whenever I used Run Build Task with MinGW-w64 on the example code provided on the page linked above, I keep running into this same error.
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to 'WinMain#16'
collect2.exe: error: ld returned 1 exit status
The important part of that bit is the undefined reference to 'WinMain#16' at the end. Apparently because the sample code I tried uses wWinMain instead of WinMain, MinGW can't find any entry point? So this would mean I can't use MinGW if I want to run this code. So what do I do instead? What compiler would actually work for compiling wWinMain?

Undefined reference to linker error when using namespaces in headers in c++ [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 1 year ago.
I've read through all similar "Undefined reference to" threads I could find but couldn't find a solution. Most of the other threads also involved classes which I don't plan to use for this. The program compiles executes normally if I define the function within the header instead of using an external .cc file. I feel like I'm missing something simple here.
This is the simplest test I could put together that recreates the issue I'm having.
Compiler: g++ (Debian 8.3.0-6) 8.3.0
hntest.h
namespace hntest
{
void pewpew();
}
hntest.cc
#include <iostream>
#include "hntest.h"
namespace hntest
{
void pewpew()
{
std::cout << "pew pew pew!!!" << std::endl;
}
}
hntestmain.cc
#include "hntest.h"
int main(int argc, char* argv[])
{
hntest::pewpew();
}
I'm attempting to compile with:
g++ -lstdc++ hntestmain.cc -o hntestmain
And I get the following linker error:
hntestmain.cc:(.text+0x10): undefined reference to `hntest::pewpew()'
collect2: error: ld returned 1 exit status
I have tried reading through the code of a couple popular C++ libraries as well as some of my own older C (not ++) code and makefiles but haven't been able to find my error. I'm admittedly both and amateur an a bit rusty.
What am I missing?
You are not actually compiling the cpp file that has the definition of pewpew.
Try:
g++ -lstdc++ hntestmain.cc hntest.cc -o hntestmain
The compiler needs to know about all the source files. The header file is dealt with during pre-process and knows to look in the same folder. You can imagine that if you have more files, say 10, 100 or 10000, this would become impossible to manage by using command line. That is why people created build systems like make, cmake and bazel.
For much greater detail see the answer here which is specific for your case of linker error.

Graphics.h c++ undefined reference to various functions like line(),initgraph() [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 11 months ago.
#include<graphics.h>
#include<stdio.h>
main()
{
int gd=DETECT,gm;
int i,x,y;
initgraph(&gd,&gm,"");
line(0,0,640,0);
line(0,0,0,480);
line(639,0,639,480);
line(639,479,0,479);
for(i=0;i<=1000;i++)
{
x=rand()%639;
y=rand()%480;
putpixel(x,y,15);
}
getch();
closegraph();
}
The Following is a Basic Graphic Program,It Shows the Errors as
undefined reference to 'initgraph'
undefined reference to 'closegraph'
undefined reference to 'line'[4 times]
undefined reference to 'putpixel'
Compiler : CodeBlocks; Language:c++;
I Have Copied the graphics.h and winbgim.h in include folder and the libbgi.a in the lib folder also i have linked all the libraries required to be linked. Please Help.
Change
initgraph(&gd,&gm,"");
to
initgraph(&gd,&gm,NULL);
for compiling:
g++ -o filename filename.cpp -lgraph
to execute:
./filename
The functions in graphics.h are only supported by old ancient Turbo C and Turbo C++ compilers. Those functions can not be used by any modern 32-bit compiler. You can either get a copy of that old MS-DOS compiler or use win32 api GDI functions or get one of several graphics libraries such as OpenGL and QT.

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

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:)

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