I am currently working on a project using netcdf-c library. I have installed it using Homebrew. I have written a small script to write a .NC file. I am using a Mac
When I compile it in CLion using make main the following gets outputted:
make main
cc main.c -o main
Undefined symbols for architecture x86_64:
"_nc_close", referenced from:
_main in main-f43ab9.o
"_nc_get_var_int", referenced from:
_main in main-f43ab9.o
"_nc_inq_varid", referenced from:
_main in main-f43ab9.o
"_nc_open", referenced from:
_main in main-f43ab9.o
"_nc_strerror", referenced from:
_main in main-f43ab9.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
This is the content of my Cmakelists.txt:
cmake_minimum_required(VERSION 3.6)
project(hello)
INCLUDE_DIRECTORIES(/usr/local/include)
LINK_DIRECTORIES(/usr/local/lib)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} cc -stdlib=lnetcdf -Wall -Werror main.c")
INCLUDE_DIRECTORIES(/usr/local/include)
LINK_DIRECTORIES(/usr/local/lib)
set(SOURCE_FILES main.c)
add_executable(hello ${SOURCE_FILES})
Despite this I am able to execute my code by using the terminal and typing:
cc -lnetcdf main.c
Could someone tell me where the problem is?
Thanks
Related
Given a very simple fortran (95) function and a very simple c++ call to the program, I should be able to compile the program using:
g++ -c main1.cpp
gfortran -c test.f95
g++ main1.o test.o -o run
However, here I get the following error:
ld: warning: object file (test.o) was built for newer macOS version (11.5) than being linked (11.0)
Undefined symbols for architecture arm64:
"hello_()", referenced from:
_main in main1.o
"__gfortran_st_write", referenced from:
_hello_ in test.o
"__gfortran_st_write_done", referenced from:
_hello_ in test.o
"__gfortran_transfer_character_write", referenced from:
hello in test.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here, adding a -v tag before the -o tag and after the -o tag and the exe run did not solve the problem, as suggested by the error message.
spent some time, with the big help of other SO user, trying to install Allegro library on osx 10.10.5
Finally it seems like it is ok, so I open the code blocks, pasted the example code( http://partitionseven.blogspot.com/2011/01/compiling-allegro-5-with-mac-os-x-snow.html), and I get an error while copiling
g++ -c /Users/lukasz/Desktop/test_allegro/test.cpp -o /Users/lukasz/Desktop/test_allegro/test.o
g++ -o /Users/lukasz/Desktop/test_allegro/test /Users/lukasz/Desktop/test_allegro/test.o
Undefined symbols for architecture x86_64:
"_al_clear_to_color", referenced from:
__al_mangled_main in test.o
"_al_create_display", referenced from:
__al_mangled_main in test.o
"_al_destroy_display", referenced from:
__al_mangled_main in test.o
"_al_flip_display", referenced from:
__al_mangled_main in test.o
"_al_install_system", referenced from:
__al_mangled_main in test.o
"_al_map_rgb", referenced from:
__al_mangled_main in test.o
"_al_rest", referenced from:
__al_mangled_main in test.o
"_main", referenced from:
implicit entry/start for main executable
(maybe you meant: __al_mangled_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
when I follow the tutorial exactly running the code from terminal with
gcc alleg5test.c -o alleg5test -L/usr/local/lib -lallegro -lallegro_main
./alleg5test
it works- i got a black screen. But how do I make it work from Code Blocks?
I am getting the following errors when I try to compile my C++ OpenGL program in Xcode on Mac OS 10.8...What should I do?
Undefined symbols for architecture x86_64:
"_aglChoosePixelFormat", referenced from:
_main in main.o
"_aglCreateContext", referenced from:
_main in main.o
"_aglDestroyContext", referenced from:
_main in main.o
"_aglDestroyPixelFormat", referenced from:
_main in main.o
"_aglSetCurrentContext", referenced from:
_main in main.o
"_aglSetFullScreen", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Since you're using AGL, looking at the reference for AGL, you need to import the framework AGL along with OpenGL.
when I try to compile and run the gmp-chudnovsky.c file found here with xcode the following errors appear:
Undefined symbols for architecture x86_64:
"_fac_clear", referenced from:
_main in main.o
"_fac_compact", referenced from:
_fac_remove_gcd in main.o
"_fac_init", referenced from:
_main in main.o
"_fac_mul", referenced from:
_bs in main.o
"_fac_mul_bp", referenced from:
_bs in main.o
"_fac_resize", referenced from:
_fac_remove_gcd in main.o
"_fac_set_bp", referenced from:
_bs in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I know the gmp library is installed correctly as I have another xcode project linking to it that is compiling correctly. Any ideas as to why this is happening?
Forgot to say I have added paths to the header file and library for GMP as well as add the -lgmp flag under Other Linker Flags
SOLVED: see this answer.
I think xcode runs in a Debug configuration first, where no optimization is performed and no inlining is carried out. This means any inline function must also be made static.
I am trying to test out a few simple Cairo programs, but I am having trouble figuring how to include the source files. I have installed the Cairo library - it's just a question of how to let gcc know...
I have the .h files (including cairo.h) installed in /usr/local/include/cairo
I have the .dylib files installed in /usr/local/lib and /usr/local/lib/cairo
Are there any other components of the installation I should be aware of? (I just did 'make install' to install the library)
I am trying to compile like this:
$ gcc cairoTest.c -I/usr/local/include/cairo -L/usr/local/lib/
My cairoTest.c file starts out with:
include <cairo.h>
gcc is finding cairo.h, but it gives the following error message. I think it is not linking to the .dylib files correctly, but I'm not sure. I'm still new to compiling/linking.
gcc cairoTest.c -I/usr/local/include/cairo -L/usr/local/lib/cairo
Undefined symbols for architecture x86_64:
"_cairo_image_surface_create", referenced from:
_main in ccVd9Pet.o
"_cairo_create", referenced from:
_main in ccVd9Pet.o
"_cairo_scale", referenced from:
_main in ccVd9Pet.o
"_cairo_set_line_width", referenced from:
_main in ccVd9Pet.o
"_cairo_set_source_rgb", referenced from:
_main in ccVd9Pet.o
"_cairo_rectangle", referenced from:
_main in ccVd9Pet.o
"_cairo_stroke", referenced from:
_main in ccVd9Pet.o
"_cairo_surface_write_to_png", referenced from:
_main in ccVd9Pet.o
"_cairo_destroy", referenced from:
_main in ccVd9Pet.o
"_cairo_surface_destroy", referenced from:
_main in ccVd9Pet.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [all] Error 1
What should I be doing differently to include the Cairo library in my compilation?
Thanks,
Try to compile with
gcc -Wall -g cairoTest.c -I/usr/local/include/cairo -L/usr/local/lib/ -lcairo -o cairoTest
(but you probably need other libraries, perhaps thru $(pkg-config --cflags --libs cairo) or similar)
And your file should start with
#include <cairo.h>