Compilation/Linking to Cairo Library - gcc

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>

Related

httpd(2.4.25), openssl(1.0.2k) - Cannot compile in macOS Sierra Error on make: Undefined symbols for architecture x86_64: "_CRYPTO_malloc_init"

Operating system is macOS Sierra, osx 10.12.3
Configure command line:
./configure --prefix=/usr/local/mac-dev-env/apache-2.4.25 --enable-so --enable-ssl --with-ssl=/usr/local/mac-dev-env/openssl-1.0.2k --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
Error created by make:
/usr/local/apr-1.5.2/build-1/libtool --silent --mode=link gcc -g -O2
-L/usr/local/mac-dev-env/openssl-1.0.2k/lib -lssl -lcrypto -lpthread \
-o ab ab.lo /usr/local/apr-util-1.5.4/lib/libaprutil-1.la -lexpat -liconv /usr/local/apr-1.5.2/lib/libapr-1.la -lpthread Undefined symbols for architecture x86_64: "_CRYPTO_malloc_init", referenced from:
_main in ab.o "_OPENSSL_init_ssl", referenced from:
_main in ab.o "_OPENSSL_sk_num", referenced from:
_ssl_proceed_handshake in ab.o "_OPENSSL_sk_value", referenced from:
_ssl_proceed_handshake in ab.o "_SSL_CTX_set_options", referenced from:
_main in ab.o "_SSL_in_init", referenced from:
_main in ab.o
_ssl_state_cb in ab.o "_TLS_client_method", referenced from:
_main in ab.o "_X509_get_version", referenced from:
_ssl_print_cert_info in ab.o "_X509_getm_notAfter", referenced from:
_ssl_print_cert_info in ab.o "_X509_getm_notBefore", referenced from:
_ssl_print_cert_info in ab.o ld: symbol(s) not found for architecture x86_64
I went to http://www.linuxfromscratch.org/blfs/view/svn/server/apache.html
From there I found two dependencies Apr-Util-1.5.4 and PCRE-8.40.
I configure the build of apr-util with:
./configure --prefix=/usr/local/mac-dev-env/apr-util-1.5.4 --with-apr=/usr/local/mac-dev-env/apr-1.5.2 --with-openssl=/usr/local/mac-dev-env/openssl-1.0.2k --with-crypto
Most important was to build apr-util with --with-openssl=/usr/local/mac-dev-env/openssl-1.0.2k --with-crypto.
I then built pcre-8.40 as I had been attempting to build with pcre-8.39.
I believe the root cause was not building with apr-util-1.5.4 with the --with-openssl=/usr/local/mac-dev-env/openssl-1.0.2k --with-crypto options.
My configuration before make for apache-2.4.25 was:
./configure --prefix=/usr/local/mac-dev-env/apache-2.4.25 --enable-so --enable-ssl --with-ssl=/usr/local/mac-dev-env/openssl-1.0.2k --with-apr=/usr/local/apr --with-apr-util=/usr/local/mac-dev-env/apr-util-1.5.4 --with-ldap

Undefined symbols for architecture x86_64 using netcdf-c

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

How do I solve the following linker error with my OpenGL program in Xcode?

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.

gmp-chudnovsky.c and xcode 4.5

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.

Compiling C/C++ application using SDL in OS X, linking problem

I'm trying to compile a C/C++ program that uses SDL on a OS X 10.6.8 but I'm having some errors on the linking stage, the code compiles but fails to like due to some missing symbols. The error is:
Undefined symbols for architecture x86_64:
"_CFBundleGetMainBundle", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
_main in libSDLmain.a(SDLMain.o)
"_CFBundleCopyBundleURL", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFURLCreateCopyDeletingLastPathComponent", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFURLGetFileSystemRepresentation", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
"_CFRelease", referenced from:
-[SDLMain setupWorkingDirectory:] in libSDLmain.a(SDLMain.o)
...
"_OBJC_CLASS_$_NSAutoreleasePool", referenced from:
objc-class-ref in libSDLmain.a(SDLMain.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [dist/linwarrior] Error 1
I checked with the file command and the libraries are either x86_64 only or universal with both i386 and x86_64 versions.
Is there a way for me to determine what exactly is causing this error? A way to check the libs that are being included or any way to help debug the problem?
I don't know if it helps but this is what my Makefile creates, I removed file names to make it short, and the KNT flag is just something I'm using for preprocessor conditions:
/opt/local/bin/g++-mp-4.5 -DKNT=1 -Wp,-M,-MP,-MT,-MF, -std=c++0x -Wall -I source -O1 -funroll-loops -c -o
Thanks.

Resources