QMake failing to use correct compiler [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have a very simple .pro file which is basically
CONFIG -= qt
HEADERS = $$files($$PWD/src/*.hpp, true);
SOURCES = $$files($$PWD/src/*.cpp, true);
LIBS += -lboost_system
LIBS += -lyaml-cpp
QMAKE_CXXFLAGS += -std=c++14
This works fine. However, 3 files in 3 different directories give WARNING: Failure to find: (filepath). Clicking on the filepath in my integrated terminal (using VSCode) opens the file just fine, so I'm not sure why this works. These files are also, for whatever reason, compiled using QMAKE_CC instead of QMAKE_CXX. This does not work as they are C++ files requiring the C++14 standard. I have temporarily fixed this by overwriting the appropriate variables, like so:
QMAKE_CC = $$QMAKE_CXX
QMAKE_CFLAGS = $$QMAKE_CXXFLAGS
However this feels like a very wrong solution.
What is going on here, and how do I solve it?

It was the semicolons. I've been writing too much C++

Related

how to link a c++ library to a c++ source code when it has a specific linker script to compile? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
i have these files:-
/lib
kernel.hpp
kernel.cpp
main.cpp
when i use
gcc -m32 -c main.cpp -lstdc++ -o main.o -llib/kernel.hpp
it says
[function name]([type of argument 1], [type of argument 2]) is not declared in this scope
how to fix?
I started writing a comment, but got to be too long, so we'll make it an answer instead. I don't think it in fact will answer your question, but it may point you in the right direction.
Let's clear up a misconception, c++ is not a superset of c; there are c constructs that c++ does not support. If your code is c++, you need to compile it with a c++ compiler. The problems you've been describing all indicate that compilation is failing; you're not at the point where the linker is involved. The compile command you provided in your question had a -c flag, which tells the compiler to stop after the compilation step - so there's no point in having a -lstd++ flag in addition. For the compiler to find kernel.hpp you need a -I flag which indicates the directory where kernel.hpp can be found. That's what I was suggesting in my first comment.
To sum up, as shown in the original question, you're using the wrong compiler and the wrong flags for what you want to do.

Pcap functions undefined reference [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to add pcap functions into my C++ project in Clion on linux.
My h file contains:
#include <pcap/pcap.h>
And the CMAKE file was updated as well.
Instead of using the next command:
if (NOT MSVC)
target_link_libraries(${TARGET} pthread)
endif()
it is now:
if (NOT MSVC)
target_link_libraries(${TARGET} pthread pcap)
endif()
still getting the next errors:
undefined reference to "pcap_open_dead"
undefined reference to "pcap_dump_open"
undefined reference to "pcap_dump_close"
undefined reference to "pcap_close"
Anyone knows how to solve it?
Thanks
Thanks for the help!
After using the VERBOSE flag I was able to see the problem.
I added the pcap flag in another CMAKE file and now it works :)

I typed g++ -o main.cpp main and I lost my program [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I've just written the following into the console:
g++ -o main.cpp main
and my main.cpp is gone.
Did I just lose my 3 hours of work?
Yes, you did. The -o flag specifies the output file (main.cpp in your case since that's the file name immediately following it):
g++ -o main.cpp main
\_________/ \__/
\ \_This is the input file.
\_____This specifies the output file.
In other words, you have told the compiler to try and compile what would normally be your executable, and write the results to your source file (overwriting it). A more suitable command would have been:
g++ -o main main.cpp
This is one of those educating moments that developers experience from time to time (including old hacks like me), the sort of thing that should convince you to do regular commits to git (or other source control system), or compile code with a build system rather than possibly complex command lines.

unistd : no such file or directory [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have the following test.cpp file :
#include <unistd>
int main()
{
return 0;
}
I just want to compile this but I still have the following :
$ g++ test.cpp
test.cpp:1:18: fatal error: unistd: No such file or directory
#include <unistd>
^
compilation terminated.
I found unistd.h at /usr/include/unistd.h. and my $LD_LIBRARY_PATH environment variable was empty so I set it at /usr/include (with export LD_LIBRARY_PATH=/usr/include) but the problem remains.
What could I do?
The name of the header is unistd.h, not unistd. And LD_LIBRARY_PATH is used to locate shared libraries, not header files.

How Can i Compile My C++ Project? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
it keeps telling me
gcc hello.cpp -o hello
gcc: error: hello.cpp: No such file or directory
gcc: fatal error: no input files
compilation terminated.
please anyone help
The source file needs to be in the same path you invoke gcc or you can put the full path in there
gcc /home/username/Desktop/hello.cpp
or you can do cd /home/username/Desktop then invoke gcc from that given path.
set your current directory where the .cpp file is