__FILE__ not giving complete file path in 64 bit configuration [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
__FILE__ is returning me the complete file path when I run the program in 32 bit.
But in 64 bit it is giving only the file name. How to resolve this?

That depends probably more on the way you drive your compiler than a 32/64 bits difference.
My expectation (and what I verified just here with gcc) is that __FILE__ gives the name as provided to the compiler. For instance
$ cat foo.c
int main() { printf("%s\n",__FILE__); }
$ gcc foo.c & ./a.out
foo.c
$ gcc ./foo.c & ./a.out
./foo.c
$ gcc `pwd`/foo.c & ./a.out
/the/full/path/as/reported/by/pwd/foo.c
similarly for include files, the path reported is the one used by the compiler to access the header, thus may depend on the way you specified the include directories.

Related

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.

What is wrong with the g++ command synatx? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to use Tensorflow shared object in my other C++ code, named as Temp_TF.cc
I am using the following command to create an executable.
g++ ../../../bazel-bin/tensorflow/cc/example/Temp_TF.so -ltensorflow_cc Temp_TF.cc -o Temp_TF
What is wrong with the following command?
I am getting the following error:
Temp_TF.cc:3:49: fatal error: tensorflow/cc/client/client_session.h: No such file or directory
compilation terminated.
I can see you're new to Stack Overflow.
Technically your question does not have enough data for us to provide an answer for sure.
However it looks to me as though you're missing a -I (capital i) directive and the compiler does not know where to find the tensorflow/cc/client/client_session.h path.
From the look of it, you could try:
g++ -I ../../../bazel-bin ../../../bazel-bin/tensorflow/cc/example/Temp_TF.so -ltensorflow_cc Temp_TF.cc -o Temp_TF
(note the -I)

Same STL files with different compilers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
There are two binary files obtained from the same source file: one compiled with clang++-3.6 and the other one with g++-4.8. In a call to a function from the stl (std::unique, in particular) gdb brings me to the same file: /usr/include/c++/4.8/bits/stl_algo.h.
I expected that the implementations would be different for each compiler though. Do clang and gcc share parts of their C++ implementations?
I expected that the implementations would be different for each compiler though. Do clang and gcc share parts of their C++ implementations?
It's not that they share the same C++ implementations, it is rather that both compilers link with the same standard c++ library by default on your system.
I presume you are on linux, almost all programs installed from package manager link against libstdc++ (provided by g++).
By default, even when compiling with clang++, libstdc++ is used, so when you include iostream for example, it uses the one from /usr/include/c++/4.8.
If you want to link against llvm c++ library, you need to install the "libc++-dev" package (name may vary depending on your distro) and compile using: -stdlib=libc++ (instead of the default: -stdlib=libstdc++).
example:
test.cpp:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Hello World!!!\n";
return 0;
}
compiling using:
$ clang++ -stdlib=libc++ -o test test.cpp
will use the header from /usr/include/c++/v1 (from llvm)
but compiling using:
$ clang++ -stdlib=libstdc++ -o test test.cpp
# or (assuming the default on your system is libstdc++)
$ clang++ -o test test.cpp
will use header from /usr/include/c++/4.8 (from g++)

why I can doesn't link ssl lib(-lssl) into so's makefile? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
there is one so, the so contain one cpp. the cpp's includes:
include "openssl/evp.h"
OpenSSL_add_all_digests()
nm the so ,and see the symbol as U:
U OpenSSL_add_all_digests
thus I check the so' Makefile,it doesn't contain lib:libssl(-L -lssl) in makefile, but it can make so successfully.
but when I write one cpp to link the so and test it, If I doesn't link the libssl with test cpp, it will popup "undefined reference" error.
How to understand it?
Generating so does NOT require all symbols to be resolved;
Generating executable requires all symbols to be resolved.
So if you generate a so, you can have "undefined reference", e.g.
testso.cpp:
void funcA();
void funcB()
{
funcA();
}
And compile and link like below:
g++ -fPIC -o testso.o -c testso.cpp # COmpile
g++ testso.o -shared -o libtestso.so # Link
You can generate libtestso.so successfully.
But if you try to link it to an executable, you need to have funcA() defined.

How do I compile a .cpp file on Linux? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm fairly comfortable with Linux and compiling things - I normally just follow the instructions and can manage to get myself out of trouble. This time, I was given a .cpp file by a random Internet citizen and I would really like to know how to compile it. Everything I seem to try (g++, c++, gcc) doesn't seem to work.
Anyhow, here's the file: http://pastebin.ca/2073013
Edit: Updated with verbose output from g++ file.cpp -o whatever: http://pastebin.ca/2073052
You'll need to compile it using:
g++ inputfile.cpp -o outputbinary
The file you are referring has a missing #include <cstdlib> directive, if you also include that in your file, everything shall compile fine.
The compiler is telling you that there are problems starting at line 122 in the middle of that strange FBI-CIA warning message. That message is not valid C++ code and is NOT commented out so of course it will cause compiler errors. Try removing that entire message.
Also, I agree with In silico: you should always tell us what you tried and exactly what error messages you got.
Just type the code and save it in .cpp format. then try "gcc filename.cpp" . This will create the object file. then try "./a.out" (This is the default object file name). If you want to know about gcc you can always try "man gcc"