How do i call External Code from Oct Files without Errors? - fortran

I want to run a Fortran program within Octave. I found a document, that has an example that i followed step by step. Here is the link. I compiled fortransub.f with the command gfortran -c fortransub.f and fortrandemo.cc with the command mkoctfile -c fortrandemo.cc. Now i have two header files. In the document it says :
Both the Fortran and C++ files need to be compiled in order for the example to work.
For me it is really a vague statement. Now to my problem. I don't know if i have to create an octfile. When i try to create one with the command mkoctfile fortrandemo.cc i get the following error:
c:/octave/octave~1.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\goebl\AppData\Local\Temp/oct-A409yh.o: in function `Ffortrandemo(octav
e_value_list const&, int)':
C:\Users\goebl\Desktop\Test_1/fortrandemo.cc:23: undefined reference to `fortransub_'
collect2.exe: error: ld returned 1 exit status
warning: mkoctfile: building exited with failure status
When i try to run the command that is the next step in the document, i get the following error:
mkoctfile fortrandemo.cc fortransub.f
gfortran: fatal error: cannot specify '-o' with '-c', '-S' or '-E' with multiple files
compilation terminated.
What did i miss or did wrong? Can someone help me out? Thank you very much!

Related

I can't run gcov on visual studio code on my cpp project; .gcda file not generating

I want to use gcov and I can't seem to get the .gcda file anywhere. I followed the official gnu guide (link) on how to use it but whenever I run g++ --coverage test.o it pops the quoted message as an error. I assume this is because the file is already created? Upon using g++ -coverage test.cpp -c it creates an .o and .gcno of the test file, not the .gcda one though:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function main': C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to WinMain'
collect2.exe: error: ld returned 1 exit status
. I have to mention that this also happens with the a.out command

Linker errors when using LLVM

I'm trying to use LLVM to build a compiler backend, but I've gotten mired in linker errors. Currently all I attempt to do is include LLVMContext.h (I'm doing the IBM tutorial), but this gives me the following linker error:
$ g++ -o compiler *.o -L/home/jakob/llvm2/lib/*.a -lantlr4-runtime
BayesBaseListener.o:(.data.rel+0x0): undefined reference to `llvm::DisableABIBreakingChecks'
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'compiler' failed
make: *** [compiler] Error 1
Any idea how to configure LLVM correctly so this doesn't happen?
The option -L is to add a path that the linker uses to search for libraries. The option -l (lower-case L) is to tell the linker to link with a specific library.
For your case though, if you want to link with all static libraries in a specific location, just list the library files as input files:
g++ -o compiler *.o /home/jakob/llvm2/lib/*.a -lantlr4-runtime
Note that I don't use the -L option.

error while invoking an online header file involving futures

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?

How to compile this C++ code on Linux with relevant header files?

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.

Linker error while compiling code in Windows

I am trying to compile my C++ code in Windows cmd.
I have implemented UnitTest++ in the project. When I run:
g++ main.cpp -IC:\Test\TreeObjModel\include -IC:\Test\unittest-cpp-master\UnitTest++
it gives the following error:
undefined reference to `UnitTest::RunAllTests()' collect2.exe: error:
ld returned 1 exit status
Can anyone help me to resolve this? Is any more info needed?
You probably are missing to compile some other cpp file (UnitTest.cpp?); or maybe you must link to some UnitTest library, where the code for UnitTest::RunAllTests() resides.
The command line option for linking a library with GCC is -l library_name.