When am trying to get pdg of a code i am getting this invalid symbol error wiht no line numbers for help.
Can any one suggest what this error means? note that code compiles and runs with g++
Question is how to get exact line number for this error.
command executed:
frama-c -continue-annot-error -kernel-verbose 3 -no-annot -no-frama-c-stdlib -cpp-command " /usr/bin/g++ -iquote../../inc -std=c++11 fPIC -Wno-write-strings -Wno-narrowing -gdwarf-3 -o test.o -c" -pdg -pdg-dot test -pdg-print test.cpp
Error message :
[kernel] computing the AST
[kernel] parsing
[kernel] Parsing FRAMAC_SHARE/libc/__fc_builtin_for_normalization.i (no preprocessing)
[kernel] Parsing /usr/local/share/frama-c/libc/__fc_builtin_for_normalization.i to Cabs
[kernel] Parsing /usr/local/share/frama-c/libc/__fc_builtin_for_normalization.i
[kernel] Converting /usr/local/share/frama-c/libc /__fc_builtin_for_normalization.i from Cabs to CIL
[kernel] Parsing test.cpp (with preprocessing)
[kernel] Parsing /tmp/test.cppe1a338.i to Cabs
[kernel] Parsing /tmp/test.cppe1a338.i
/tmp/test.cppe1a338.i:1:[kernel] user error: Invalid symbol
[kernel] user error: stopping on file "test.cpp"
that has errors.
[kernel] Frama-C aborted: invalid user input.
Frama-C is meant to analyze C code, not C++ code. These are two different languages, and unless you write plain C (with the caveat that some constructions that look syntactically similar in both languages have in fact different semantics), there is no way Frama-C can parse your test.cpp file.
In addition, as mentioned by Anne in comment, the -cpp-command you have given is incorrect: you have asked g++ to provide a binary file, whereas Frama-C is expecting pre-processed C. As a matter of fact, the error line is mentioned in your log: /tmp/test.cppe1a338.i:1:, but this is meaningless since test.cppe1a338 is a binary file. With an appropriate -cpp-command (such as the one Frama-C gives you by default), Frama-C will find #line annotations which will allow it to report any error at the appropriate location in the original file instead of the intermediate result.
Related
I have written a template function wait_for_all(vector) which blocks until every future in the vector is ready and then exits.
The problem and an implementation were originally given by Stroustrup in "The C++ Programming Language", 4th ed, pg 1243. However, I have changed the implementation, since Stroustrup's didn't handle exceptions thrown by a passed future. I have successfully tested my implementation: http://coliru.stacked-crooked.com/a/43bc327ac9f77f48. This solution combines the function and the tester in a single source file.
However, when I split the function and the tester into 2 separate files on coliru, I run into an error for the tester.
Header: http://coliru.stacked-crooked.com/a/5f3e11b783baf2e7 : It's OK
Tester: http://coliru.stacked-crooked.com/a/9badf42d85fc4e96 : Gives an error
The compilation output for the tester is:
ln -s /Archive2/5f/3e11b783baf2e7/main.cpp wait_for_all.h #link to the header file
clang++ -std=c++14 -stdlib=libc++ -O2 -Wall -Wextra -pedantic-errors main.cpp -o wait_for_all_test
./wait_for_all_test
/usr/bin/ld: /tmp/main-28d9f5.o: undefined reference to symbol 'pthread_setspecific##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
bash: line 11: ./wait_for_all_test: No such file or directory
What exactly is this error and how do I fix it?
I am trying to compile this C++ code in my Linux box using g++ but it fails with the following error:
enigma/Enigma# g++ -I . main.cpp -o main
In file included from machine.h:14:0,
from tests.h:13,
from main.cpp:10:
plug.h:13:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
#import "util.h"
^~~~~~
/tmp/ccxyoEC2.o: In function `main':
main.cpp:(.text+0x10): undefined reference to `test_machine_encode_decode()'
collect2: error: ld returned 1 exit status
The error indicates that the compiler cannot find the tests.h file present in the same folder. How can I compile and run this code?
I now understand that I needed to link the object files together, I did so using:
g++ -c *.cpp
g++ *.o -o enig
It still does not work though, the resulting binary executes with ./enig but is broken and does not function as intended:
Entire encoded message: TZQA
Decoding now...
Entire decoded message: AHOJ
Entire encoded message: HBIU
Decoding now...
Entire decoded message: AHOJ
Entire encoded message: ZSNE
Decoding now...
Entire decoded message: AHOJ
Entire encoded message: ICRH
It just keeps encoding and decoding those random texts as opposed to the functionality mentioned on the git page I shared above.
Anything I'm missing?
The error indicates that the compiler cannot find the tests.h file present in the same folder.
No, it doesn't. In fact, the compiler successfully compiled main.cpp.
The error indicates that the linker cannot find test_machine_encode_decode. This is hardly surprising, since test_machine_encode_decode is defined in test.cpp. You have to link the object files of main.cpp and test.cpp to get a complete executable.
If you look at the actual code, you'll see that main only calls the test_machine_encode_decode() Unit-test. You'll have to implement the functionality from the readme yourself or you search through the git history and try to find out, if the program actually worked in the past.
I have successfully run llvm opt with my toy transformation pass but do not see how to use 'opt' with built-in transformation passes http://llvm.org/docs/Passes.html#introduction
I have an empty hi.c file
int main(){
}
For example, if I want to use -instcount pass,
opt -instcount hi.c
gives me strange error.
opt: hi.c:1:1: error: expected top-level entity
int main(){
^
Use opt -instcount hi.bc does not work neither, with
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.
If I use opt -inst-count -f hi.bc, the output is a messy bitcode.
Question: how should we use 'opt' with built-in transformation passes (those from the link above)? Thanks for your ideas. 'opt -help' says
opt [options] <input bitcode file>
but my example above 'opt -instcount hi.bc' does not work as expected (see above).
At first: opt only works on bitcode / readable LLVM IR files. So passing a .c file will never work.
You have to compile the .c file first with clang:
clang -emit-llvm in.c -o input.bc
The Warning you encounter says basicly everything:
WARNING: You're attempting to print out a bitcode file. This is
inadvisable as it may cause display problems. If you REALLY want to
taste LLVM bitcode first-hand, you can force output with the `-f'
option.
opt has as output the probably modified bitcode file and since you do not support an output file it will print it to stdout. That is why you get "messy" bitcode.
To use opt the way it should be you can use /dev/null to get rid of the output:
opt -inst-count input.bc -o /dev/null
or support an output file
opt -inst-count input.bc -o output.bc
or print the output as readable LLVM IR to stdout
opt -inst-count input.bc -S
or print the ouptut as readable LLVM IR file to disk
opt -inst-count input.bc -S -o output.ll
I'm trying to compile bitcoin on my EC2 instance, and I've run into a problem I can't figure out. The build script stops on the following command
g++ -c -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g -DMSG_NOSIGNAL=0 -DBOOST_SPIRIT_THREADSAFE -DUSE_UPNP=1 -DUSE_IPV6=1 -I/home/ec2-user/bitcoin/src/leveldb/include -I/home/ec2-user/bitcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -I"/home/ec2-user/bitcoin/src" -I"/home/ec2-user/bitcoin/src/obj" -I"/usr/local/include" -I"/usr/include/openssl" -MMD -MF obj/alert.d -o obj/alert.o alert.cpp
by returning the following error(s)
In file included from /usr/include/sys/socket.h:40:0,
from compat.h:19,
from netbase.h:11,
from util.h:27,
from alert.h:13,
from alert.cpp:11:
/usr/include/bits/socket.h:231:5: error: expected identifier before numeric constant
/usr/include/bits/socket.h:231:5: error: expected ‘}’ before numeric constant
/usr/include/bits/socket.h:231:5: error: expected unqualified-id before numeric constant
In file included from compat.h:19:0,
from netbase.h:11,
from util.h:27,
from alert.h:13,
from alert.cpp:11:
/usr/include/sys/socket.h:254:1: error: expected declaration before ‘}’ token
I've tried compiling with the -std=c++0x option set, but it made no difference. That was the only thing I've been able to come up with.
I'd wager that some header file you have is #defineing a macro that interferes with socket.h. Are you able to compile a program that only includes <sys/socket.h>, with no other inclusions?
The next thing to check is to look at /usr/include/bits/socket.h and see what's on line 231 (where the first error occurs). If the code looks ok, then the next step is to see what the preprocessed source looks like. To get the preprocessed output, replace the -c option with -E on the command line, and change the -o obj/alert.o option to -o alert.ii to put the preprocessor output into the file alert.ii.
If you compare the content of alert.ii with /usr/include/bits/socket.h, you can see if it's getting compiled as expected or not. In particular, if there's a macro which defines something into something unexpected, you'll see code which is clearly wrong at the location the compiler is pointing out.
I'm trying to compile a simple "Hello World" program in Linux using Eclipse, but I always get this:
Building target: hello
Invoking: GCC C++ Linker
g++ -o "hello" ./src/hello.o
./src/hello.o: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [hello] Error 1
**** Build Finished ****
Does anyone have an idea what the problem is?
Just remove the object file.
This error most likely appeared after the previous build was interrupted and object file was not generated completely.
Just as an info if someone comes around here.
Another problem (with the same error) could be, that you are using ccache for faster compilation. In this case, the corrupt *.o file is there as well. So for that reason you have to clean the cache with
ccache -C (note the upper case C!)
Wasted me hours the first time ;-)
I think
g++ -o "hello" ./src/hello.o
should be ./src/hello.(c | cpp | cc depending on your language type)