Ocaml link error objective-c (cocoa) - objective-c

I'm trying to call some objective-c code from within ocaml.
stubs.m
#include <Cocoa/Cocoa.h>
#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/callback.h>
#include <caml/alloc.h>
#include <caml/fail.h>
CAMLprim value ml_NSLog (value str)
{
CAMLparam1 (str);
NSLog (#"%s", String_val (str));
CAMLreturn (Val_unit);
}
It gets compiled with the following command to stubs.o:
cc -Wextra -Wall -Werror -O -g -std=c99 -pedantic-errors -Wsign-compare -Wshadow -I /Users/Iwan/.opam/4.02.3/lib/ocaml -c -o stubs.o stubs.m
My ocaml code in index.ml is:
external _NSLog: string -> unit = "ml_NSLog"
let log s = _NSLog s
let () = log "hello"
When I execute ocamlopt -o app index.ml stubs.o I get:
Undefined symbols for architecture x86_64:
"_NSLog", referenced from:
_ml_NSLog in stubs.o
(maybe you meant: _ml_NSLog)
"___CFConstantStringClassReference", referenced from:
CFString in stubs.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking
Why do I get the error in this case?

The solution was brutally simple:
ocamlopt -cclib "-framework Cocoa" -o app index.ml stubs.o
I had to pas "-framework Cocoa" as option to the c linker...

Related

How CMake automatically detects header dependencies

I wonder how CMake automatically detects that main.cpp depends on header.h
// header.h
int f() {
return 0;
}
// main.cpp
#include "header.h"
int main() {
return f();
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(Cppref)
add_executable(main main.cpp)
When I run cmake . -B build it creates the following make target in ./build/CMakeFiles/main.dir/build.make
CMakeFiles/main.dir/main.cpp.o: CMakeFiles/main.dir/compiler_depend.ts
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/nikolay/Cpp/Train/Cppref/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/main.dir/main.cpp.o"
/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/main.dir/main.cpp.o -MF CMakeFiles/main.dir/main.cpp.o.d -o CMakeFiles/main.dir/main.cpp.o -c /home/nikolay/Cpp/Train/Cppref/main.cpp
Pay attention to the -MD compiler option, as
it is used to dump dependencies visible to the preprocessor.
So after the first build it will create ./build/CMakeFiles/main.dir/main.cpp.o.d with the following content
CMakeFiles/main.dir/main.cpp.o: /home/nikolay/Cpp/Train/Cppref/main.cpp \
/home/nikolay/Cpp/Train/Cppref/header.h
So whenever you change header.h, the target main.o will be rebuilt.

Compiling cpputest with mingw-w64

I'm trying to compile cpputest with mingw-w64 but can't make it work and I can't find any resources on how to do that. So hopefully this question will help others in the future.
I would like to compile cpputest using mingw-w64, preferably without installing MSYS2 or other packages.
I have mingw-w64 i686-8.1.0-posix-dwarf-rt_v6-rev0 installed. I've cloned cpputest from here.
I tried following Compiling Google test with Mingw-w64 and Compiling and using CppUTest 3.8 under MSYS2/MinGW32 by calling CMake with:
cmake ^
-G "MinGW Makefiles" ^
-D CMAKE_C_COMPILER=gcc.exe ^
-D CMAKE_CXX_COMPILER=g++.exe ^
-D CMAKE_MAKE_PROGRAM=mingw32-make.exe ^
-D C++11=ON ^
.
Which yields:
-------------------------------------------------------
CppUTest Version 3.8
Current compiler options:
CC: C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gcc.exe
CXX: C:/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/g++.exe
CppUTest CFLAGS: -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h" -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Wstrict-prototypes
CppUTest CXXFLAGS: -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h" -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast -Wno-c++14-compat
CppUTest LDFLAGS:
Features configured in CppUTest:
Memory Leak Detection: ON
Compiling Extensions: ON
Support Long Long: OFF
Use CppUTest flags: ON
Using Standard C library: ON
Using Standard C++ library: ON
Using C++11 library: ON
Generating map file: OFF
Compiling with coverage: OFF
Compile and run self-tests ON
Run self-tests separately OFF
-------------------------------------------------------
Running make fails with:
>mingw32-make.exe
Scanning dependencies of target CppUTest
[ 1%] Building CXX object src/CppUTest/CMakeFiles/CppUTest.dir/CommandLineArguments.cpp.obj
In file included from C:/git/tdd/cpputest/include/CppUTest/Utest.h:34,
from C:/git/tdd/cpputest/include/CppUTest/TestHarness.h:39,
from C:\git\tdd\cpputest\src\CppUTest\CommandLineArguments.cpp:29:
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:183:31: error: 'nullptr_t' does not name a type
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:183:31: note: 'nullptr_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:42:1:
+#include <cstddef>
C:/git/tdd/cpputest/include/CppUTest/SimpleString.h:183:31:
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
mingw32-make.exe[2]: *** [src\CppUTest\CMakeFiles\CppUTest.dir\build.make:63: src/CppUTest/CMakeFiles/CppUTest.dir/CommandLineArguments.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:886: src/CppUTest/CMakeFiles/CppUTest.dir/all] Error 2
mingw32-make.exe: *** [Makefile:140: all] Error 2
I tried the obvious solution of adding cstddef to SimpleString.h:
--- a/include/CppUTest/SimpleString.h
+++ b/include/CppUTest/SimpleString.h
## -180,6 +180,9 ## SimpleString BracketsFormattedHexString(SimpleString hexString);
* Specifically nullptr_t is not officially supported
*/
#if __cplusplus > 199711L && !defined __arm__
+
+#include <cstddef>
+
SimpleString StringFrom(const nullptr_t value);
#endif
But that still fails with the same error.
So I tried following Build error with CMake and MSYS2 mingw-w64 by installing MSYS2 and then mingw-w64, CMake and Ninja. That gives:
-------------------------------------------------------
CppUTest Version 3.8
Current compiler options:
CC: C:/msys64/mingw64/bin/cc.exe
CXX: C:/msys64/mingw64/bin/c++.exe
CppUTest CFLAGS: -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h" -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Wstrict-prototypes
CppUTest CXXFLAGS: -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h" -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast
CppUTest LDFLAGS:
Features configured in CppUTest:
Memory Leak Detection: ON
Compiling Extensions: ON
Support Long Long: OFF
Use CppUTest flags: ON
Using Standard C library: ON
Using Standard C++ library: ON
Using C++11 library: OFF
Generating map file: OFF
Compiling with coverage: OFF
Compile and run self-tests ON
Run self-tests separately OFF
-------------------------------------------------------
Compiling with cmake -G Ninja . && ninja fails with:
include/CppUTest/SimpleString.h:183:31:
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
[10/98] Building CXX object src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj
FAILED: src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj
C:\msys64\mingw64\bin\c++.exe -DCPPUTEST_HAVE_STRDUP=1 -DHAVE_CONFIG_H -D_TIMESPEC_DEFINED=1 -I. -Iinclude -Isrc/CppUTest/../../include -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorNewMacros.h" -include "C:/git/tdd/cpputest/include/CppUTest/MemoryLeakDetectorMallocMacros.h" -Wall -Wextra -pedantic -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wsign-conversion -Wno-padded -Wno-long-long -Woverloaded-virtual -Wno-old-style-cast -O2 -g -DNDEBUG -MD -MT src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj -MF src\CppUTest\CMakeFiles\CppUTest.dir\TestMemoryAllocator.cpp.obj.d -o src/CppUTest/CMakeFiles/CppUTest.dir/TestMemoryAllocator.cpp.obj -c src/CppUTest/TestMemoryAllocator.cpp
In file included from include/CppUTest/Utest.h:34,
from include/CppUTest/TestHarness.h:39,
from src/CppUTest/TestMemoryAllocator.cpp:28:
include/CppUTest/SimpleString.h:183:31: error: 'nullptr_t' does not name a type
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
include/CppUTest/SimpleString.h:183:31: note: 'nullptr_t' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
include/CppUTest/SimpleString.h:42:1:
+#include <cstddef>
include/CppUTest/SimpleString.h:183:31:
SimpleString StringFrom(const nullptr_t value);
^~~~~~~~~
ninja: build stopped: subcommand failed.
Thanks!!
Turns out this was a bug in CppUtest.
## -562,7 +562,7 ## SimpleString BracketsFormattedHexString(SimpleString hexString)
* Specifically nullptr_t is not officially supported
*/
#if __cplusplus > 199711L && !defined __arm__
- SimpleString StringFrom(const nullptr_t value)
+ SimpleString StringFrom(const std::nullptr_t value)
{
(void) value;
return "(null)";
It's fixed since Dec. 5th, 2019.
https://github.com/leonardopsantos/cpputest/commit/cb8c457dda6741ede7009103db99967b5f27c969

bazel build aot with cross tool failed in platform.h fatal error 'mutex' file not found

I am trying aot cross compiling with bazel.But failed in platform.h fatal error 'mutex' file not found.I can build with bazel without cross compile setting, and I can exec the binary in host.
My environment is below
x86-64 ubuntu14.04
target:arm-linux-gnueabihf
tensorflow:Head of maste cd5f3b67fca88217776522182481b0c128db5af9
bazel:0.5.4 installed by apt-get install
My test code is below.
#define EIGEN_USE_THREADS
#define EIGEN_USE_CUSTOM_THREAD_POOL
#include <iostream>
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/compiler/aot/tests/test_graph_tfmatmul.h" // generated
int main(int argc, char** argv) {
Eigen::ThreadPool tp(2); // Size the thread pool as appropriate.
Eigen::ThreadPoolDevice device(&tp, tp.NumThreads());
foo::bar::MatMulComp matmul;
matmul.set_thread_pool(&device);
// Set up args and run the computation.
const float args[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
std::copy(args + 0, args + 6, matmul.arg0_data());
std::copy(args + 6, args + 12, matmul.arg1_data());
matmul.Run();
// Check result
if (matmul.result0(0, 0) == 58) {
std::cout << "Success" << std::endl;
} else {
std::cout << "Failed. Expected value 58 at 0,0. Got:"
<< matmul.result0(0, 0) << std::endl;
}
return 0;
}
I modified the some files to compile.
add cross compile setting to WORKSPACE file
new_local_repository( name = "linaroLinuxGcc49Repo", build_file =
"compilers/linaro_linux_gcc_4.9.BUILD", path =
"compilers/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf", )
add build setting in /tensorflow/compiler/aot/tests/BUILD
cc_binary(
name = "my_binary",
srcs = [
"my_code.cc", # include test_graph_tfmatmul.h to access the generated header
],
deps = [
":test_graph_tfmatmul", # link in the generated object file
"//third_party/eigen3",
],
linkopts = [
"-lpthread",
] )
Below is the build command I did.
bazel build --copt=-Wno-c++11-narrowing --cxxopt='-std=c++11'
//tensorflow/compiler/aot/tests:my_binary
--host_crosstool_top=#bazel_tools//tools/cpp:toolchain --crosstool_top=//tools/arm_compiler:toolchain --cpu=armeabi-v7a --verbose_failures
Finally I get the error below.
(root) user-name#machine-name:repo
[master]$ bazel build --copt=-Wno-c++11-narrowing
--cxxopt='-std=c++11' //tensorflow/compiler/aot/tests:my_binary --host_crosstool_top=#bazel_tools//tools/cpp:toolchain --crosstool_top=//tools/arm_compiler:toolchain --cpu=armeabi-v7a --verbose_failures WARNING: /home/user-name/tensorflow/repo/tensorflow/core/BUILD:1772:1: in
includes attribute of cc_library rule
//tensorflow/core:framework_headers_lib: '../../external/nsync/public'
resolves to 'external/nsync/public' not below the relative path of its
package 'tensorflow/core'. This will be an error in the future. Since
this rule was created by the macro 'cc_header_only_library', the error
might have been caused by the macro implementation in
/home/user-name/tensorflow/repo/tensorflow/tensorflow.bzl:1029:30
WARNING:
/home/user-name/tensorflow/repo/tensorflow/contrib/learn/BUILD:15:1:
in py_library rule //tensorflow/contrib/learn:learn: target
'//tensorflow/contrib/learn:learn' depends on deprecated target
'//tensorflow/contrib/session_bundle:exporter': No longer supported.
Switch to SavedModel immediately. WARNING:
/home/user-name/tensorflow/repo/tensorflow/contrib/learn/BUILD:15:1:
in py_library rule //tensorflow/contrib/learn:learn: target
'//tensorflow/contrib/learn:learn' depends on deprecated target
'//tensorflow/contrib/session_bundle:gc': No longer supported. Switch
to SavedModel immediately. INFO: Analysed target
//tensorflow/compiler/aot/tests:my_binary (0 packages loaded). INFO:
Found 1 target... ERROR:
/home/user-name/.cache/bazel/_bazel_user-name/6d2eb697f6f4dfadad89ea8a861fded5/external/nsync/BUILD:397:1:
C++ compilation of rule '#nsync//:nsync_cpp' failed (Exit 1): clang
failed: error executing command (cd
/home/user-name/.cache/bazel/_bazel_user-name/6d2eb697f6f4dfadad89ea8a861fded5/execroot/org_tensorflow
&& \ exec env - \
PWD=/proc/self/cwd \
PYTHON_BIN_PATH=/home/user-name/.pyenv/versions/anaconda3-4.4.0/bin/python
\
PYTHON_LIB_PATH=/home/user-name/.pyenv/versions/anaconda3-4.4.0/lib/python3.6/site-packages
\
TF_NEED_CUDA=0 \
TF_NEED_OPENCL=0 \ tools/arm_compiler/linaro_linux_gcc/clang_bin/clang -target
armv7a-arm-linux-gnueabif
'--sysroot=external/linaroLinuxGcc49Repo/arm-linux-gnueabihf/libc'
'-mfloat-abi=hard' -nostdinc -isystem /usr/lib/clang/3.6/include
-isystem external/linaroLinuxGcc49Repo/lib/gcc/arm-linux-gnueabihf/4.9.4/include
-isystem external/linaroLinuxGcc49Repo/arm-linux-gnueabihf/libc/usr/include
-isystem external/linaroLinuxGcc49Repo/lib/gcc/arm-linux-gnueabihf/4.9.4/include-fixed
-isystem external/linaroLinuxGcc49Repo/arm-linux-gnueabihf/libc/usr/include
-isystem external/linaroLinuxGcc49Repo/include/c++/4.9.4 -U_FORTIFY_SOURCE -fstack-protector -fPIE '-fdiagnostics-color=always' -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 -DNDEBUG -ffunction-sections -fdata-sections -Wno-c++11-narrowing -MD -MF bazel-out/clang_linux_armhf-py3-opt/bin/external/nsync/_objs/nsync_cpp/external/nsync/internal/sem_wait.d
-iquote external/nsync -iquote bazel-out/clang_linux_armhf-py3-opt/genfiles/external/nsync -iquote
external/bazel_tools -iquote
bazel-out/clang_linux_armhf-py3-opt/genfiles/external/bazel_tools
-isystem external/nsync/public -isystem bazel-out/clang_linux_armhf-py3-opt/genfiles/external/nsync/public
-isystem external/bazel_tools/tools/cpp/gcc3 -x c++ '-std=c++11' -DNSYNC_ATOMIC_CPP11 -DNSYNC_USE_CPP11_TIMEPOINT -I./external/nsync//platform/c++11 -I./external/nsync//platform/gcc -I./external/nsync//platform/arm -I./external/nsync//public -I./external/nsync//internal -I./external/nsync//platform/posix '-D_POSIX_C_SOURCE=200809L' -pthread -no-canonical-prefixes
-Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c
external/nsync/internal/sem_wait.c -o
bazel-out/clang_linux_armhf-py3-opt/bin/external/nsync/_objs/nsync_cpp/external/nsync/internal/sem_wait.o)
warning: unknown warning option '-Wunused-but-set-parameter'; did you
mean '-Wunused-parameter'? [-Wunknown-warning-option] warning: unknown
warning option '-Wno-free-nonheap-object'; did you mean
'-Wno-sequence-point'? [-Wunknown-warning-option] In file included
from external/nsync/internal/sem_wait.c:16:
./external/nsync//platform/c++11/platform.h:29:10: fatal error:
'mutex' file not found
#include
^ 2 warnings and 1 error generated. Target //tensorflow/compiler/aot/tests:my_binary failed to build INFO:
Elapsed time: 0.917s, Critical Path: 0.15s FAILED: Build did NOT
complete successfully
Error occures in "C++ compilation of rule '#nsync//:nsync_cpp' failed (Exit 1):" .
Befause of "./external/nsync//platform/c++11/platform.h:29:10: fatal error: 'mutex' file not found
#include
"
The file mutex is exist in ./compilers/gcc-linaro-4.9-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/include/c++/4.9.4/mutex.
I think path above is setted in the build output line "-isystem external/linaroLinuxGcc49Repo/include/c++/4.9.4"
How could I set the path to mutex? for cross compiling nsync?
I made a mistake when I edit CROSSTOOL file.
If you know detail, please refer below.
https://github.com/bazelbuild/bazel/issues/3836
thanks!

trouble building trilininos using cmake

I am trying to build trilinos in fedora25 guest (virtualbox). Followed procedure described here:
http://iltabiai.github.io/peridynamics/fedora/tips/2016/04/20/Peridigm141-Fedora23.html
I had to adapt the build script from above link so that it could find Netcdf and HDF5 on my system.
trilinos builds with these errors in CMakeError.log :
Performing C++ SOURCE FILE Test FINITE_VALUE_HAVE_GLOBAL_ISNAN failed with the following output:
Change Dir: /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_44df3/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_44df3.dir/build.make CMakeFiles/cmTC_44df3.dir/build
gmake[1]: Entering directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_44df3.dir/src.cxx.o
/usr/lib64/mpich/bin/mpicxx -O2 -ansi -pedantic -ftrapv -Wall -Wno-long-long -std=c++11 -DFINITE_VALUE_HAVE_GLOBAL_ISNAN -o CMakeFiles/cmTC_44df3.dir/src.cxx.o -c /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx: In function ‘int main()’:
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:6:10: error: ‘isnan’ was not declared in this scope
isnan(x);
^
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:6:10: note: suggested alternative:
In file included from /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:2:0:
/usr/include/c++/6.3.1/cmath:662:5: note: ‘std::isnan’
isnan(_Tp __x)
^~~~~
CMakeFiles/cmTC_44df3.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_44df3.dir/src.cxx.o' failed
gmake[1]: *** [CMakeFiles/cmTC_44df3.dir/src.cxx.o] Error 1
gmake[1]: Leaving directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_44df3/fast' failed
gmake: *** [cmTC_44df3/fast] Error 2
Source file was:
#include <cmath>
int main()
{
double x = 1.0;
isnan(x);
return 0;
}
Performing C++ SOURCE FILE Test FINITE_VALUE_HAVE_GLOBAL_ISINF failed with the following output:
Change Dir: /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_4cb6e/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_4cb6e.dir/build.make CMakeFiles/cmTC_4cb6e.dir/build
gmake[1]: Entering directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_4cb6e.dir/src.cxx.o
/usr/lib64/mpich/bin/mpicxx -O2 -ansi -pedantic -ftrapv -Wall -Wno-long-long -std=c++11 -DFINITE_VALUE_HAVE_GLOBAL_ISINF -o CMakeFiles/cmTC_4cb6e.dir/src.cxx.o -c /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx: In function ‘int main()’:
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:6:10: error: ‘isinf’ was not declared in this scope
isinf(x);
^
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:6:10: note: suggested alternative:
In file included from /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:2:0:
/usr/include/c++/6.3.1/cmath:635:5: note: ‘std::isinf’
isinf(_Tp __x)
^~~~~
CMakeFiles/cmTC_4cb6e.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_4cb6e.dir/src.cxx.o' failed
gmake[1]: *** [CMakeFiles/cmTC_4cb6e.dir/src.cxx.o] Error 1
gmake[1]: Leaving directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_4cb6e/fast' failed
gmake: *** [cmTC_4cb6e/fast] Error 2
Source file was:
#include <cmath>
int main()
{
double x = 1.0;
isinf(x);
return 0;
}
Determining if the pthread_create exist failed with the following output:
Change Dir: /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_78ecb/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_78ecb.dir/build.make CMakeFiles/cmTC_78ecb.dir/build
gmake[1]: Entering directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_78ecb.dir/CheckSymbolExists.c.o
/usr/lib64/mpich/bin/mpicc -o CMakeFiles/cmTC_78ecb.dir/CheckSymbolExists.c.o -c /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_78ecb
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_78ecb.dir/link.txt --verbose=1
/usr/lib64/mpich/bin/mpicc -rdynamic CMakeFiles/cmTC_78ecb.dir/CheckSymbolExists.c.o -o cmTC_78ecb
/usr/bin/ld: CMakeFiles/cmTC_78ecb.dir/CheckSymbolExists.c.o: undefined reference to symbol 'pthread_create##GLIBC_2.2.5'
/usr/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_78ecb.dir/build.make:97: recipe for target 'cmTC_78ecb' failed
gmake[1]: *** [cmTC_78ecb] Error 1
gmake[1]: Leaving directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_78ecb/fast' failed
gmake: *** [cmTC_78ecb/fast] Error 2
File /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>
int main(int argc, char** argv)
{
(void)argv;
#ifndef pthread_create
return ((int*)(&pthread_create))[argc];
#else
(void)argc;
return 0;
#endif
}
Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_5fb6c/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_5fb6c.dir/build.make CMakeFiles/cmTC_5fb6c.dir/build
gmake[1]: Entering directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5fb6c.dir/CheckFunctionExists.c.o
/usr/lib64/mpich/bin/mpicc -DCHECK_FUNCTION_EXISTS=pthread_create -o CMakeFiles/cmTC_5fb6c.dir/CheckFunctionExists.c.o -c /usr/share/cmake/Modules/CheckFunctionExists.c
Linking C executable cmTC_5fb6c
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_5fb6c.dir/link.txt --verbose=1
/usr/lib64/mpich/bin/mpicc -DCHECK_FUNCTION_EXISTS=pthread_create -rdynamic CMakeFiles/cmTC_5fb6c.dir/CheckFunctionExists.c.o -o cmTC_5fb6c -lpthreads
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_5fb6c.dir/build.make:97: recipe for target 'cmTC_5fb6c' failed
gmake[1]: *** [cmTC_5fb6c] Error 1
gmake[1]: Leaving directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_5fb6c/fast' failed
gmake: *** [cmTC_5fb6c/fast] Error 2
Performing C++ SOURCE FILE Test HAVE_TEUCHOS_LAPACKLARND failed with the following output:
Change Dir: /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_93b6d/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_93b6d.dir/build.make CMakeFiles/cmTC_93b6d.dir/build
gmake[1]: Entering directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_93b6d.dir/src.cxx.o
/usr/lib64/mpich/bin/mpicxx -O2 -ansi -pedantic -ftrapv -Wall -Wno-long-long -std=c++11 -DHAVE_TEUCHOS_LAPACKLARND -o CMakeFiles/cmTC_93b6d.dir/src.cxx.o -c /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx: In function ‘int main()’:
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:12:38: error: narrowing conversion of ‘0.0’ from ‘double’ to ‘int’ inside { } [-Wnarrowing]
int seed[4] = { 0.0, 0.0, 0.0, 1.0 };
^
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:12:38: error: narrowing conversion of ‘0.0’ from ‘double’ to ‘int’ inside { } [-Wnarrowing]
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:12:38: error: narrowing conversion of ‘0.0’ from ‘double’ to ‘int’ inside { } [-Wnarrowing]
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:12:38: error: narrowing conversion of ‘1.0e+0’ from ‘double’ to ‘int’ inside { } [-Wnarrowing]
CMakeFiles/cmTC_93b6d.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_93b6d.dir/src.cxx.o' failed
gmake[1]: *** [CMakeFiles/cmTC_93b6d.dir/src.cxx.o] Error 1
gmake[1]: Leaving directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_93b6d/fast' failed
gmake: *** [cmTC_93b6d/fast] Error 2
Return value: 1
Source file was:
#define F77_BLAS_MANGLE(name,NAME) name ## _
#define DLARND_F77 F77_BLAS_MANGLE(dlarnd,DLARND)
extern "C" { double DLARND_F77(const int* idist, int* seed); }
int main()
{
const int idist = 1;
int seed[4] = { 0.0, 0.0, 0.0, 1.0 };
double val = DLARND_F77(&idist, seed);
return (val < 0.0 ? 1 : 0);
}
Performing C++ SOURCE FILE Test HAVE_CXX_PRAGMA_WEAK failed with the following output:
Change Dir: /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/gmake" "cmTC_21bab/fast"
/usr/bin/gmake -f CMakeFiles/cmTC_21bab.dir/build.make CMakeFiles/cmTC_21bab.dir/build
gmake[1]: Entering directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_21bab.dir/src.cxx.o
/usr/lib64/mpich/bin/mpicxx -O2 -ansi -pedantic -ftrapv -Wall -Wno-long-long -std=c++11 -DHAVE_CXX_PRAGMA_WEAK -o CMakeFiles/cmTC_21bab.dir/src.cxx.o -c /home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx: In function ‘int main()’:
/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp/src.cxx:14:22: warning: the address of ‘void A::theFunction()’ will never be NULL [-Waddress]
if (A::theFunction != NULL) {
^
Linking CXX executable cmTC_21bab
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_21bab.dir/link.txt --verbose=1
/usr/lib64/mpich/bin/mpicxx -O2 -ansi -pedantic -ftrapv -Wall -Wno-long-long -std=c++11 -DHAVE_CXX_PRAGMA_WEAK -rdynamic CMakeFiles/cmTC_21bab.dir/src.cxx.o -o cmTC_21bab
CMakeFiles/cmTC_21bab.dir/src.cxx.o: In function `main':
src.cxx:(.text.startup+0x25): undefined reference to `A::theFunction()'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_21bab.dir/build.make:97: recipe for target 'cmTC_21bab' failed
gmake[1]: *** [cmTC_21bab] Error 1
gmake[1]: Leaving directory '/home/peri/packages/trilinos-12.10.1-Source/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_21bab/fast' failed
gmake: *** [cmTC_21bab/fast] Error 2
Source file was:
#include <iostream>
namespace A {
// theFunction never gets defined, because we
// don't link with a library that defines it.
// That's OK, because it's weak linkage.
#pragma weak theFunction
extern void theFunction ();
}
int main() {
std::cout << "Hi! I am main." << std::endl;
if (A::theFunction != NULL) {
// Should never be called, since we don't link
// with a library that defines A::theFunction.
A::theFunction ();
}
return 0;
}
how can these errors be eliminated?

Compiling object c (.m) file to an object file(.o) in osx

Thanks for reviewing the problem. There is an object c file called try.m, and I complie it to an object file try.o with the command:
gcc -c try.m -o try.o -framework Foundation
the try.h is
int print_word( void );
The try.m is:
#include "try.h"
#import <Foundation/Foundation.h>
int print_word( void )
{
NSLog (#"say hello");
return 0;
}
Additionly, there is a main.c file, which contain the main() function, and it looks:
#include <stdio.h>
#include "try.h"
int main()
{
printf( "This is main\n");
}
I compile main.c to main.o by the following command:
gcc -o main.o -c main.c
Then, I link the main.o and try.o to form the executable file main:
gcc -o main main.o try.o
After these steps, the following errors happened:
enter image description here
The errors are:
Undefined symbols for architecture x86_64:
"_NSLog", referenced from:
_print_word in try.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How could these errors be solved?
You need to link against the Foundation framework. You can do it all in a single command: gcc main.c try.m -framework Foundation.