I was trying to compile hello.cob to hello.c:
$ ls
hello.cob
$ cobc -x -C hello.cob
$ ls
hello.c hello.c.h hello.c.l.h hello.cob
But clang failed to compile hello.c to executable file:
$ clang hello.c
/tmp/hello-479acf.o: In function `main':
hello.c:(.text+0x1e): undefined reference to `cob_init'
hello.c:(.text+0x2a): undefined reference to `cob_stop_run'
/tmp/hello-479acf.o: In function `sampleCOBOL_':
hello.c:(.text+0x98): undefined reference to `cob_module_global_enter'
hello.c:(.text+0x133): undefined reference to `cob_display'
hello.c:(.text+0x13f): undefined reference to `cob_stop_run'
hello.c:(.text+0x15a): undefined reference to `cob_check_version'
hello.c:(.text+0x33d): undefined reference to `cob_set_cancel'
hello.c:(.text+0x38e): undefined reference to `cob_fatal_error'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is hello.cob (can be compiled by cobc -x hello.cob):
IDENTIFICATION DIVISION.
PROGRAM-ID. sampleCOBOL.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
I'm quite sure clang doesn't fail to compile the C source as you don't ave any C compiler warnings or errors.
It cannot link the generated object file because you didn't told clang to link against libcob and there is no "magic" for clang to know where to find its symbols. Adding -lcob to your clang invocation may be enough already.
If you want to know how cobc invokes the compiler/linker add -v to your cobc invocation.
Note: if this version of cobc was built with gcc it defaults to use gcc, too. You can see this with cobc --info which also shows if any of the built-in commands is override by environment variables.
Additional note: cobc does not only call a C compiler/linker, it also generates C code specific for the compiler it was built with. The most important part concerning the C generation is -f[no-]computed-goto, just in case the C compiler complains (which it doesn't in your case).
Related
I'm using the following options:
touch foo.f90; gfortran -cpp -E -dM foo.f90
, but when I remove the -E flag I get this error:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
As I used 'touch' the file is empty.
The -E flag is described in the manual.
If you use the -E option, nothing is done except preprocessing. Some
of these options make sense only together with -E because they cause
the preprocessor output to be unsuitable for actual compilation.
It makes the compiler to print the preprocessed source code instead of compiling it. That means preprocessed by cpp, the C preprocessor.
If your source code is not a valid Fortran program, then trying to actually compile it (without the -E flag) naturally leads to some kind of error message.
I'm trying to install OpenDetection on Ubuntu 16.04.
I have installed all the dependencies according to here except OpenCV.
This is the CMake command I used for OpenCV:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_VTK=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -DOPENCV_EXTRA_MODULES_PATH=/home/tiestu/Documents/GitRepository/OpenCV3/opencv_contrib/modules /home/tiestu/Documents/GitRepository/OpenCV3/opencv
But when I try to make OpenCV, I receive this error which I believe has something to do with VTK!
I have configured VTK using latest prebuilt binary version of cmake with the default settings, as per installation instructions. but this error says:
vtkGenericDataArrayLookupHelper.h:72:23: error: ‘nullptr’ was not declared in this scope
The full error/warning section of the build output is:
In file included from /usr/local/include/vtk-7.1/vtkGenericDataArray.h:72:0,
from /usr/local/include/vtk-7.1/vtkAOSDataArrayTemplate.h:35,
from /usr/local/include/vtk-7.1/vtkIntArray.h:33,
from /usr/local/include/vtk-7.1/vtkCellTypes.h:42,
from /usr/local/include/vtk-7.1/vtkPolyData.h:64,
from /usr/local/include/vtk-7.1/vtkPolyDataAlgorithm.h:36,
from /usr/local/include/vtk-7.1/vtkAppendPolyData.h:35,
from /home/tiestu/Documents/GitRepository/OpenCV3/opencv/modules/viz/src/precomp.hpp:56,
from /home/tiestu/Documents/GitRepository/OpenCV3/opencv/release/modules/viz/opencv_viz_pch_dephelp.cxx:1:
/usr/local/include/vtk-7.1/vtkGenericDataArrayLookupHelper.h:72:5: warning: identifier ‘nullptr’ is a keyword in C++11 [-Wc++0x-compat]
: AssociatedArray{nullptr}, SortedArray(nullptr),
^
/usr/local/include/vtk-7.1/vtkGenericDataArrayLookupHelper.h: In constructor ‘vtkGenericDataArrayLookupHelper<ArrayTypeT>::vtkGenericDataArrayLookupHelper()’:
/usr/local/include/vtk-7.1/vtkGenericDataArrayLookupHelper.h:72:22: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
: AssociatedArray{nullptr}, SortedArray(nullptr),
^
/usr/local/include/vtk-7.1/vtkGenericDataArrayLookupHelper.h:72:23: error: ‘nullptr’ was not declared in this scope
: AssociatedArray{nullptr}, SortedArray(nullptr),
^
/usr/local/include/vtk-7.1/vtkGenericDataArrayLookupHelper.h:73:15: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
FirstValue{nullptr}, SortedArraySize{0}
^
/usr/local/include/vtk-7.1/vtkGenericDataArrayLookupHelper.h:73:41: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
FirstValue{nullptr}, SortedArraySize{0}
^
modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/build.make:62: recipe for target 'modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/opencv_viz_pch_dephelp.cxx.o' failed
make[2]: *** [modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/opencv_viz_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:6005: recipe for target 'modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/all' failed
make[1]: *** [modules/viz/CMakeFiles/opencv_viz_pch_dephelp.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
Does it matter what version of compiler (11 or 0x) I've used? If so what version should I use?
You need to use a compiler that supports the version of OpenCV that you are using, and the version of the C++ language that it uses, which from your error and warning diagnostic messages, looks be at least C++11.
You can read the documentation for the compiler version you have to see what C++ language versions it supports. There's also a support information table on cppreference.com.
It's interesting that you get such errors and warnings at all. Libraries should be able to tell CMake in its CMake configuration what C++ language version it uses in its source files, and CMake would keep track of that requirement to make sure the correct compiler flags get used wherever needed. See the target_compile_features() command for more info on that.
I have been using clang-3.5 to happily build bitcode versions of musl libc and
use the result to produce nice stand alone executables.
Recent attempts with clang-3.8 have not been so happy. It seems that
the bitcode clang-3.8 generates uses functions defined in
compiler-rt/lib/builtins
Typical examples of functions I find polluting the bitcode are mulxc3, mulsc3, and muldc3. I can solve this by linking against libgcc, or even the llvm alternative if I had any clear idea of what that was. Though I would rather prevent the problem from happening in the first place.
I have seen mention of flags like rtlib=compiler-rt etc, but have found precious little documentation on the subject.
So here are some simple questions.
Is it possible to prevent clang from using the compiler-rt/lib/builtins
in the emitted bitcode? Or if not
Does llvm produce a version of libgcc that I could use. Actually I would
probably build a bitcode version of it, but that is besides the point.
Love to hear some guidance on this.
Added 12/8/2016: So I will illustrate my issues with a particular workflow that
people can reproduce if they wish, or, more likely, just point out where I am being stupid.
So start by checking out:
musllv
and follow the instructions in the README.to compile (here I am using clang-3.8 on ubuntu 14.04)
WLLVM_CONFIGURE_ONLY=1 CC=wllvm ./configure --target=LLVM --build=LLVM
make
cd lib
extract-bc -b libc.a
you will also need the bitcode of a simple executable. I will use nweb.c here.
wllvm nweb.c -o nweb
extract-bc nweb
Now we can do things like:
clang -static -nostdlib nweb.bc libc.a.bc crt1.o libc.a -o nweb
This workflow goes smoothly for clang-3.5 but for clang-3.8 we get:
clang -static -nostdlib nweb.bc libc.a.bc crt1.o libc.a -o nweb
/tmp/libc-f734a3.o: In function `cpowl':
libc.a.bc:(.text+0xbb9a): undefined reference to `__mulxc3'
/tmp/libc-f734a3.o: In function `cpowf':
libc.a.bc:(.text+0x38f7d): undefined reference to `__mulsc3'
/tmp/libc-f734a3.o: In function `csqrt':
libc.a.bc:(.text+0x78fc3): undefined reference to `__muldc3'
/tmp/libc-f734a3.o: In function `cpow':
libc.a.bc:(.text+0xafafc): undefined reference to `__muldc3'
clang-3.8: error: linker command failed with exit code 1 (use -v to seeinvocation)
So as #paul-brannan points out we could try
clang -static -nostdlib --rtlib=compiler-rt nweb.bc libc.a.bc crt1.o libc.a -o nweb
But this is where I am probably being stupid, because I get:
clang-3.8: warning: argument unused during compilation: '--rtlib=compiler-rt'
irregardless of whether I use it as a linking or compiling flag.
OK so I finally managed to make headway on this. I built llvm-3.8.1 together with the compiler-rt project using wllvm and wllvm++.
One of the build products was libclang_rt.builtins-x86_64.a,
and from this archive I was able to extract the bitcode module
libclang_rt.builtins-x86_64.bc
using the command:
extract-bc -b libclang_rt.builtins-x86_64.a
This bitcode module has definitions for those pesky instrinsics like
__mulxc3, __mulsc3, and __muldc3.
Hallelujah!
I'm trying to use clang with OpenMPI. I have set the wrapper compiler using
export OMPI_CC=clang
When I try to verify the compiler mpicc is invoking by using
mpicc --showme:command
I get this error
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
However, a sample mpi code runs fine using regular mpicc and mpirun commands, I guess its sticking back to the default mpicc compiler and not clang. I need to use certain clang functionalities for the OpenMPI code. How do I rectify this error.
I have been trying to enable the gold linker on FreeBSD to use the link time optimizations. I made gold from the binutils under /usr/ports. After building binutils using make -k install clean i got ld under /usr/bin and in the directory /usr/local/bin i got ld, ld.gold and ld.bfd.
Now while trying to use link time optimization for the simple example programs here http://llvm.org/docs/GoldPlugin.html (a.c and b.c under the heading 'Examples of Link Time Optimization') i entered the four commands as follows:
clang -flto a.c -c -o a.o
ar q a.a a.o
clang b.c -c -o b.o
clang -flto a.a b.o -o main
I got the following error:
usr/bin/ld: unrecogonized option '-plugin'
usr/bin/ld: use the --help option for usage information
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there the problem with the linker that ld.gold is not being called. Should I replace the ld with ld.gold? Does the linker looks in the right directiry for the .so plugins?
The LLVMgold.so and libLTO.so shared objects are in the directory /usr/local/llvm-devel/lib/.
I cannot find the directory where clang is installed. I am not sure where to make the bfd-plugins directory and add the symlinks to LLVMgold.so and libLTO.so.
I am using freebsd 10.1 release. How to enable the gold linker for link time optimizations?
also how can I enable it to be the default linker?
You may want to use ld.gold instead of ld. It is installed at /usr/local/bin/ld.gold. If you are using a Makefile, it would work by setting LD variable to ld.gold, either by modifying your Makefile or specifying it on command line. Example in case you are using lang/clang37:
gmake all CC=clang37 LD=ld.gold
EDIT:
It would be even more neat if you add -fuse-ld=gold to your LDFLAGS:
LDFLAGS=-fuse-ld=gold
I'm not sure ld.bfd allows plugins, but I could be wrong.
Your /usr/bin/ld should be a symlink to whatever linker you want. You can change which linker is used by using binutils-config. Check the man-page here: http://www.linuxhowtos.org/manpages/8/binutils-config.htm. I realise this is a Linux link, but it's directed at binutils itself rather than linux-specifically.
It should be something along the lines binutils-config --gold.
On my Gentoo box it is binutils --linker=gold
EDIT: As pointed out, binutils-config doesn't work on BSD it seems. You can still manually update the symlinks though, the downside is that there might be a few of them.
You can find out which ld is used by your compiler by using gcc -print-prog-name=ld or clang -print-prog-name=ld. The file printed should be a symlink you can re-create to point to ld.gold as oposed to ld.bfd.