So I'm attempting to compile a header file, a main file, and a function definition file together in Geany. I'm using the command
user#cu-cs-vm:~/Dropbox$ g++ Assignment4.cpp CommunicationNetwork.cpp CommunicationNetwork.h -o Assignment4
But when it executes, I get the error message:
cc1plus: out of memory allocating 3355443200 bytes after a total of 548864 bytes.
Any idea of what could be happening?
Related
I'm writing some code for an assignment for a CS class at my university. This program is supposed to read in a .DAT file from the command line, assign the values in the file to an array, and then take that array and compute its average. The only issue I have is that I keep getting this error when I try to compile my code:
/usr/bin/ld:seven.dat: file format not recognized; treating as linker script
/usr/bin/ld:seven.dat:1: syntax error
collect2: error: ld returned 1 exit status
I've tried looking around on Google/StackOverflow a bit, but my programming knowledge is too limited to really understand what's going on, so I have no idea where my errors are. I'm compiling the program with this command:
g++ lab5.1.cpp seven.dat -Wall -o myprog
I can post some/all of the code if needed also.
The problem is that you are trying to compile the .dat file as part of the build process when creating your myprog executable. That is wrong. Build the executable first, then pass the .dat file to your program when you run it, eg:
g++ lab5.1.cpp -Wall -o myprog
myprog seven.dat
Inside your code, you will receive the seven.dat filename in your main() function's argv[] parameter. You can then open the .dat file and read its content as needed.
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 Fortran code that is compiled using mpiifort. I have an error when running this code using mpirun. Bellow I am pasting both how I compile and run. I get two warnings that are ignored, and one error. I believe the error is the real issue, not the warnings. I would greatly appreciate any help!
mpiifort mycode.f90 -r8 -O2 -xHost -override-limits -o output.out
[me#gauss ORIGINALV]$ mpirun -n 1 ./output.out
[gauss:31148] mca: base: component_find: unable to open /usr/local/openmpi/1.10.0/lib/openmpi/mca_plm_tm: libtorque.so.2: cannot open shared object file: No such file or directory (ignored)
[gauss:31148] mca: base: component_find: unable to open /usr/local/openmpi/1.10.0/lib/openmpi/mca_ras_tm: libtorque.so.2: cannot open shared object file: No such file or directory (ignored)
./output.out: symbol lookup error: /srv/home/shaorshadze/intel/compilers_and_libraries_2016.1.150/linux/mpi/intel64/lib/libmpifort.so.12: undefined symbol: MPI_UNWEIGHTED
Primary job terminated normally, but 1 process returned a non-zero exit code.. Per user-direction, the job has been aborted.
mpirun detected that one or more processes exited with non-zero status, thus causing the job to be terminated. The first process to do so was:
I'm running into a strange issue when I try to compile the following simple C++11 code on my machine:
#include <boost/thread/thread.hpp>
It compiles fine with g++ foo.cpp -o foo but chokes on g++ -c -std=c++11 foo.cpp -o foo with the following error:
In file included from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/functional:56:0,
from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/memory:81,
from /usr/local/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/include/boost/smart_ptr/shared_ptr.hpp:27,
from /usr/local/include/boost/shared_ptr.hpp:17,
from /usr/local/include/boost/thread/pthread/thread_data.hpp:10,
from /usr/local/include/boost/thread/thread.hpp:17,
from foo.cpp:1:
./tuple:1:1: error: stray ‘\317’ in program
./tuple:1:1: error: stray ‘\372’ in program
./tuple:1:1: error: stray ‘\355’ in program
./tuple:1:1: error: stray ‘\376’ in program
... Additional lines omitted
I'm at a loss. Especially since I've been able to compile other programs against C++11 without any issue. Any ideas?
I'm running OS X v10.7.4 (Lion) and GCC 4.7.1.
That's because you have a file in your current directory named tuple that is included instead of the standard tuple header. Probably because of some -I. in the compilation line.
The strays characters in the error messages are simply the first bytes of the file not in the allowed character set, in octal.