Remote Development CLion and Raspberry Pi Model 3B+ wiringPi.h problem - cmake

I am using Raspberry Pi model 3b+ and my gpio pins on raspberry are working properly.
gpio -g mode 18 out
gpio -g write 18 0
gpio -g write 18 1
When I connect to the raspberry pi via ssh and run these commands, I get output from the gpio pin on the 18th output.
But this code block I wrote with the CLion ide does not work. wiringPi.h is not linking correctly.
#include <iostream>
#include <wiringPi.h>
int main()
{
std::cout << "Hello, World Test!" << std::endl;
wiringPiSetup();
pinMode(18, OUTPUT);
while (true) {
digitalWrite(18, 1);
delay(500);
digitalWrite(18, 0);
delay(500);
}
return 0;
}
CMakeLists.txt File Content:
cmake_minimum_required(VERSION 3.18)
project(SDEmbedded)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lwiringPi")
add_executable(SDEmbedded main.cpp)
Toolchains:
Error Message:
/usr/bin/ld: CMakeFiles/SDEmbedded.dir/main.cpp.o: in function `main':
/tmp/tmp.LnoD9QNyYS/main.cpp:7: undefined reference to `wiringPiSetup'
/usr/bin/ld: /tmp/tmp.LnoD9QNyYS/main.cpp:9: undefined reference to `pinMode'
/usr/bin/ld: /tmp/tmp.LnoD9QNyYS/main.cpp:12: undefined reference to `digitalWrite'
/usr/bin/ld: /tmp/tmp.LnoD9QNyYS/main.cpp:13: undefined reference to `delay'
/usr/bin/ld: /tmp/tmp.LnoD9QNyYS/main.cpp:14: undefined reference to `digitalWrite'
/usr/bin/ld: /tmp/tmp.LnoD9QNyYS/main.cpp:15: undefined reference to `delay'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/SDEmbedded.dir/build.make:103: SDEmbedded] Error 1
make[2]: *** [CMakeFiles/Makefile2:95: CMakeFiles/SDEmbedded.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:102: CMakeFiles/SDEmbedded.dir/rule] Error 2
make: *** [Makefile:137: SDEmbedded] Error 2

Related

Linking C++ on Rust: undefined reference to `operator delete(void*)' and `__gxx_personality_v0', libstdc++ missing?

I'm trying to build a cpp cmake project and link to my Rust project.
cmake_minimum_required(VERSION 3.0)
set (CMAKE_CXX_STANDARD 17)
project(ZLMediaKit_LIB CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
set(ENABLE_TESTS OFF FORCE)
option(ENABLE_TESTS OFF)
set(ENABLE_OPENSSL FALSE FORCE)
option(ENABLE_OPENSSL OFF)
add_subdirectory(ZLMediaKit)
add_library(libzlmediakit_cpp_interface STATIC interface.cpp)
target_include_directories(libzlmediakit_cpp_interface PUBLIC
.
${CMAKE_CURRENT_SOURCE_DIR}/ZLMediaKit/src
${CMAKE_CURRENT_SOURCE_DIR}/ZLMediaKit/3rdpart/ZLToolKit/src)
target_link_libraries(libzlmediakit_cpp_interface zlmediakit zltoolkit mpeg mov flv libstdc++)
install(TARGETS libzlmediakit_cpp_interface DESTINATION .)
Here's my build.rs:
extern crate cmake;
use cmake::Config;
fn main()
{
let dst = Config::new("zlmediakit_lib").build();
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=libzlmediakit_cpp_interface");
}
But I'm getting undefined reference errors:
ong)':
/usr/include/c++/9/ext/new_allocator.h:128: undefined reference to `operator delete(void*)'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `ZLRTSPClient::~ZLRTSPClient()':
/home/dev/orwell/liborwell_rust/zlmediakit_rust/zlmediakit_lib/ZLRTSPClient.h:14: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `std::default_delete<ZLRTSPClient>::operator()(ZLRTSPClient*) const':
/usr/include/c++/9/bits/unique_ptr.h:81: undefined reference to `operator delete(void*, unsigned long)'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o): in function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: /usr/include/c++/9/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
/usr/bin/ld: /home/dev/orwell/liborwell_rust/zlmediakit_rust/target/debug/build/zlmediakit_rust-499cc82f14515635/out/liblibzlmediakit_cpp_interface.a(interface.cpp.o):(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
I've researched and found some answers (Link error "undefined reference to `__gxx_personality_v0'" and g++) that old me to link against libstdc++. As you see, I'm already doing that.
If I try to compile the CMake project alone, it links sucessfully. However then I compile everything from the Rust side, it gives this error.
Complete output of rust compilation

'Undefined reference to "WinMain#16" ' while setting up SDL2 with CMake

So I want to learn how to use CMake (specifically in CLion), and right now I'm trying to set up SDL2 with it. I got FindSDL2.cmake in my Modules folder, and this is my code:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
project(CLion_Tests)
set(CMAKE_CXX_STANDARD 11)
set(SDL2_PATH "C:/Users/Lerchi/Downloads/SDL/SDL2main/64")
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
add_executable(CLion_Tests main.cpp)
target_link_libraries(CLion_Tests ${SDL2_LIBRARY})
and main.cpp is just this:
#include <iostream>
#include <SDL.h>
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_EVERYTHING);
std::cout << "Hello, World!" << std::endl;
return 0;
}
The error I'm getting is
CMakeFiles\CLion_Tests.dir/objects.a(main.cpp.obj):main.cpp:(.text+0x1c): undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CLion_Tests.exe] Error 1
CMakeFiles\CLion_Tests.dir\build.make:87: recipe for target 'CLion_Tests.exe' failed
mingw32-make.exe[1]: *** [CMakeFiles/CLion_Tests.dir/all] Error 2
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/CLion_Tests.dir/all' failed
mingw32-make.exe: *** [all] Error 2
Makefile:82: recipe for target 'all' failed

Ocaml link error objective-c (cocoa)

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...

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.