i was compiling a lex.yy.cc and it is giving me the following error: FlexLexer.h no such file or directory
I have tried to put this .h on the same file as the code persé, and it stills gives me the error, i tried all the following ways to compile it and the web is not giving me a clear answer to my problem:
g++ lex.yy.cc
g++ lex.yy.cc -lfl
g++ lex.yy.cc -lm
g++ lex.yy.cc -lfl -lm
gcc lex.yy.cc -lm
gcc lex.yy.cc
nothing happend, i really dont know what else to try, i have changed the enviroments variables a 100 times and doesnt work. Please help :)
As #user2912836 stated try the -I command, I've run into the same problem before and its worked for me.
More info on directory searching: https://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#SEC1s
By "nothing happened", did you mean it was giving you the same error, or it just didn't output anything?
If it's the first case, I suggest you use the -I option to tell gcc where your headers file are.
If it's the second case, it probably compiled. See if there is an a.out file in your directory.
Related
There are similar questions but their answers did not work for my issue.
I have a c++ program with #include <boost/test/unit_test.hpp> on top (among other includes).
To compile correctly, if I understood, I should do the command:
g++ -g -L/path_to_boost_lib -lboost_lib myprog.cpp -o myprog.exe
If i do a locate, I get /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.
Hence I edited my call to g++ by doing:
g++ -g -L/usr/lib/x86_64-linux-gnu -lboost_unit_test_framework myprog.cpp -o myprog.exe
But I still get errors of the type undefined reference to boost::unit_test.
I also tried the option -I/usr/include/ which contains the boost folder, without success.
It's because of the order. The GCC linker goes through the artifacts left-to-right, and every unknown symbol it encounters in an object file must be resolved by an artifact occurring afterwards.
The right command is thus:
g++ -g myprog.cpp -L/usr/lib/x86_64-linux-gnu -lboost_unit_test_framework -o myprog.exe
See this answer for a more thorough explanation.
I suggest using a build tool like CMake that takes care of such low-level details for you.
First I tried just downloading what you get after searching mingw64 windows. That didn't work. While searching for a solution I came across this, where the answer includes what seems to be a legit version of mingw64.
This being probably the third or fourth mingw64 I've downloaded, I was happy to see a g++64.exe which I assumed would take care of everything. It doesn't, after compiling with g++64 -o hello.exe -c hello.cpp and running hello I get an error saying This version of [...]\hello.exe is not compatible[...].
What am I doing wrong? I've tried -m64. Is there some additional setting I need to change? Should I post what I get for g++64 -v?
Your command is wrong, you're not creating a .exe file, but an object file that you need to link to produce an executable. Do it like this:
g++64 -o hello.exe hello.cpp
The -c argument tells the compiler to just compile but not link your code. You can do the above in 2 steps, compile and link:
g++64 -c -o hello.o hello.cpp
g++64 -o hello.exe hello.o
I have been trying to compile a simple C++ program with the googletest libraries. I have gotten this to work using g++, however the project will soon become large and I want to be able to automate the compilation using make. I installed GNU make for windows which I have tested on another program and it works. However when I try and use make to compile my googletest project I get the following error:
ld.exe: cannot find -lgtest
Here is the contents of my makefile:
all: test.exe
test.exe: main.cpp
g++ -o test.exe .\main.cpp .\sample1.h .\sample1.cc .\sample1_unittest.cc -ID:\...\gtest\include -LD:\D...\gtest\lib\ -lgtest_main -lgtest -Wall
clean:
rm test.o test.exe
The weird thing is that if I run the same code from the command line, as follows, it works perfectly an I end up with my test.exe.
g++ -o test.exe .\main.cpp .\sample1.h .\sample1.cc .\sample1_unittest.cc -ID:\...\gtest\include -LD:\D...\gtest\lib\ -lgtest_main -lgtest -Wall
Does anyone know what this could be caused by and how to fix it?
Ok, I managed to find the problem! I'm still not sure why this is the case but apparently in make you have to specify paths like so:
-LD:\...\gtest\lib
And not like this (note the extra ):
-LD:\...\gtest\lib\
The error message makes sense since it must have been trying to search for the library in a path that looks something like this:
-LD:\...\gtest\lib\\
Which would obviously not work. I guess what threw me off was that the code worked when executed from the command line. It took me a while to see the inconstancy in my path specification and figure out that make doesn't want the extra '\'. Hopefully this will prevent someone else for wasting as much time as I did.
i'm like working client-server application..
I'm trying to run the server - CountryServer.c file..
i tried with g++ and gcc and i got compilation errors.. i even googled and got answers.. sadly i still got the same errors..
with gcc
oh, i even also tried to enable std=c++11
and std=c++0x but it says no input files.. >.<
i enabled using this command:
gcc -std=c++11
and also tried this other enabled commands:
g++ -std=c++1 CountryServer.c -o CountryServer
and
g++ -Wall -g -std=c++11 CountryServer.c -o CountryServer
for both 0x & 11
andd,i've also checked which version has the iostream and also checked the gcc or g++ version >.<
i really dont understand and dont know what other ways/solutions/methods..
please help me! thanks ! :D
for iostream error,
can you please try compiling with g++
or
compiling gcc with option -lstdc++
gcc -o -lstdc++
Whenever I try to compile a c++ code with g++ on terminal, I can't seem to get g++ to output any error messages even though I am certain that there are errors that should be caught during compile time (such as syntax, reference types...).
I tried several ways such as this make file:
all:
g++ -W -Wall -Werror main.cpp
All it does is output:
make: *** [all] Error 1
which isn't that useful, obviously...
Typing things like this:
g++ -W -Wall -Werror main.cpp
directly to terminal (without the make file) doesn't output any messages at all.
However this successfully outputs all of the errors while compiling:
cc main.cpp
My question is: how do I make g++ to output error messages so I can know where to correct my code?
Just guessing - is it possible your terminal doesn't print stderr? Say, for example, it moves it to a log file or something?
Try running
g++ [whatever your arguments are] |& cat
(this is if you use tcsh)
or
g++ [whatever] 2>&1 | cat
if you use bash.
Try something simple like this:
g++ -c main.cpp
Make reports an error when one of it's tasks returns non-0 status. If g++ silently returns non-0 - well, i suppose it's broken somehow. Check $? after you've run g++. Also, try g++ --version - will it report anything at all? Also you could run it under debugger, just to be sure.
Try adding a line like
#warning hello from here
(or perhaps #error instead of #warning) into main.cc near the beginning (perhaps as the first line).
If
gcc -Wall -v main.cc
don't give any output (notably no warnings or errors) that means that your gcc is broken. Perhaps type /usr/bin/gcc instead of just gcc
BTW, Apple don't like GCC (because they dont like its GPLv3+ license). Maybe it is worth your time to build [using e.g. ..../configure --program-suffix=-local] and install a newer GCC (perhaps from the released source tar ball of the compiler). Current version is 4.8.1!