Build problems with PostGIS 2.4.4 on MacOS 10.12 - postgis

I'm attempting to build PostGIS 2.4.4, on MacOS 10.12, using MacPorts for the various libraries. The build is currently failing with (while linking shp2pgsql):
Undefined symbols for architecture x86_64:
"_iconv", referenced from:
_utf8 in shp2pgsql-core.o
"_iconv_close", referenced from:
_utf8 in shp2pgsql-core.o
"_iconv_open", referenced from:
_utf8 in shp2pgsql-core.o
ld: symbol(s) not found for architecture x86_64
Some research has revealed that there's an issue with the libiconv that MacPorts installs, and one should use the system library, but I haven't had success using --with-libiconv-prefix and --with-libiconv pointing at the system library in /usr. Has anyone done this successfully?

I was insufficiently diligent about trying config options; setting it to explicitly use the MacPorts installed libconv worked:
./configure --with-libiconv-prefix=/opt/local --with-libiconv=/opt/local

You do realize that MacPorts offers a port of that version of postgis?
$ port info postgis2
postgis2 #2.4.4 (databases, gis)
Variants: comments, gui, [+]postgresql10, postgresql93, postgresql94, postgresql95, postgresql96, proj4, [+]raster, sfcgal, [+]topology, universal
Description: PostGIS 2 adds geometrical, geographical and topological types, and functions operating thereon, to the PostGreSQL database. The 2.0 release also provides raster handling and basic 3D geometry capacities
(TIN and polyhedra).
Homepage: http://postgis.refractions.net/
Build Dependencies: autoconf, automake, libtool, libxslt
Library Dependencies: geos, proj, libiconv, libxml2, json-c, postgresql10, gdal
Conflicts with: postgis
Platforms: darwin
License: GPL-2+
Maintainers: Email: vince#macports.org
Policy: openmaintainer

This problem occurs when you mismatch headers and libraries. E.g. compiling with the iconv headers from /usr/include but linking against the iconv library from /opt/local/lib will cause this problem.
That's because the iconv headers installed by MacPorts contain a #define iconv libiconv, which is the symbol provided by the library. It is not a MacPorts decision to ship this define, btw; it's the upstream default.

Related

dyld: Library not loaded: But Library seems entirely unrelated

I have an interesting issue: I have a C++ project (built with CMake/make) and probably some dependency I had compiled from source had their dependency updated via brew upgrade. Now, when I make, I get
dyld: Library not loaded: /usr/local/opt/x265/lib/libx265.179.dylib
Referenced from: /usr/local/opt/ffmpeg/lib/libavcodec.58.dylib
Reason: image not found
Abort trap: 6
However, the application does not use ffmpeg, libavcodec or similar directly. It does use OpenCV (which may link against those, I don't know), and the Spinnaker SDK for FLIR cameras (which depends on libavcodec).
Question: What command line tools can I use, to recursively search through the linked libraries for a binary to find the offending (missing) library? I ran otool -L on my binary, but it does not directly link against the offending libs.

Undefined symbols for architecture x86_64 with Json-C

Basically it's my first stack overflow question, so I am sorry for any inaccuracies/stupid questions here + I have tried for 3 days to solve my problem using all other answers people gave on similar questions, but either way I don't know Cmake enough or I am doing something wrong from the very beginning.
I've installed Json-c through Homebrew (brew install json-c). I am using Clion on macOS which uses Cmake.
I have modified my CmakeLists:
cmake_minimum_required(VERSION 3.10)
project(Project C)
set(CMAKE_C_STANDARD 99)
INCLUDE_DIRECTORIES(/usr/local/Cellar/json-c/0.13.1/include/json-c)
LINK_DIRECTORIES(/usr/local/Cellar/json-c/0.13.1/lib)
add_executable(Project main.c functions.c functions.h exp_functions.c exp_functions.h)
TARGET_LINK_LIBRARIES(Project)
but I am not sure how to set arguments for TARGET_LINK_LIBRARIES.
When I am trying to build the project it gives me this:
Undefined symbols for architecture x86_64:
"_json_object_new_double", referenced from:
_GenerateJson in functions.c.o
"_json_object_new_object", referenced from:
_GenerateJson in functions.c.o
"_json_object_new_string", referenced from:
_GenerateJson in functions.c.o
"_json_object_object_add", referenced from:
_GenerateJson in functions.c.o
"_json_object_to_json_string", referenced from:
_GenerateJson in functions.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
From what I have found on the web, someone had similar problem (https://github.com/json-c/json-c/issues/235), but after I have installed the package through Brew, I don't have any "json-c" files/folders in /usr/local/lib. There's only "json-c" alias in usr/local/include to brew directory.
I have tried to install json-c using instructions that are provided on repository site (https://github.com/json-c/json-c), but after that I had no clue how to set CmakeLists.txt to make the project work
What am I doing wrong. I am fresh at programming at all + I don't know much of the cmake and how macOS/Homebrew manages files when I am installing new packages through git clone.
You are missing something like
LDFLAGS+= -ljson-c
to link with the library. It was in the setup instructions for CMake in their README.

Compiling a C program that uses OpenGl 4 in Mac OS X

So I am learning OpenGL 4 from openglbook.
I copied and pasted the simple window creating program in my editor and followed Compiling OpenGL programs on OS X by using
gcc -o hello hello.c -framework OpenGL -framework GLUT
I got the following error:
Undefined symbols for architecture x86_64:
"_glewGetErrorString", referenced from:
_Initialize in chapter-c8ba2d.o
"_glewInit", referenced from:
_Initialize in chapter-c8ba2d.o
"_glutInitContextFlags", referenced from:
_InitWindow in chapter-c8ba2d.o
"_glutInitContextProfile", referenced from:
_InitWindow in chapter-c8ba2d.o
"_glutInitContextVersion", referenced from:
_InitWindow in chapter-c8ba2d.o
"_glutSetOption", referenced from:
_InitWindow in chapter-c8ba2d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I understand correctly, the problem is tha -framework GLUT means that you're linking against the GLUT framework shipped by Apple with macOS and located inside /System/Library/Frameworks folder. This GLUT implementation unfortunately lacks some functionality provided by current version of FreeGLUT. And OpenGLBook.com tutorials use some of this functionality, thus, as it is mentioned many times here, the code examples have to be compiled with FreeGLUT.
There are, of course, few ways this can be done. The easiest one is by installing freeglut by means of the infamous Homebrew package manager and then setting up the CMake project as described below.
So, first install freeglut
brew install freeglut
Then setup CMake project by adding the following lines into CMakeLists.txt
find_package(FreeGLUT CONFIG REQUIRED)
find_package(glew CONFIG REQUIRED)
link_libraries(FreeGLUT::freeglut GLEW::GLEW)

libiconv issue when compiling SDL 2.0 on Mac OS X 10.6

I'm trying to compile SDL 2.0 on OS X 10.6, but I've been getting this message:
Undefined symbols:
"_libiconv_open", referenced from:
_SDL_iconv_string in SDL_iconv.o
_SDL_iconv_string in SDL_iconv.o
"_libiconv", referenced from:
_SDL_iconv in SDL_iconv.o
_SDL_iconv_string in SDL_iconv.o
"_libiconv_close", referenced from:
_SDL_iconv_string in SDL_iconv.o
_SDL_iconv_string in SDL_iconv.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
I've read the issues over at https://github.com/mxcl/homebrew/issues/894 and How to replace MacPort's libiconv with Mac's default 64-bit version? to see if either of them help. I uninstalled everything that MacPorts had since those two seemed to suggest that the issue was related to multiple versions of the same library (libiconv it had installed had way too many dependencies to manually uninstall them all, and I didn't need them anymore), but am still getting the same error. Any ideas?
So it turns out after uninstalling the MacPorts copy, I still had 2 copies of libiconv on my computer that were different. One was in /usr/lib, and the other was in /usr/local/lib. Compiling with the one in /usr/lib produced the error above, however adding -L/usr/local/lib to the EXTRA_LDFLAGS variable in the Makefile worked.
I found a simple solution. Just add 2 more parameters when configure SDL source:
./configure CPPFLAGS='-I/opt/local/include' LDFLAGS='-L/opt/local/lib'

Problem using C file and Cocoa classes together

I have imported the ffmpeg and SDL libraries into my Xcode project for a Cocoa application.
My project builds and runs successfully with these libraries when my project contains only Cocoa classes, but when I include a C file in my project, the build fails with one warning and 35 errors:
The warning is:
ld: warning: in /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/libgcc.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
and the errors:
"___gedf2", referenced from:
_eval_expr in libavcodec.a(eval.o)
_quantize_lpc_coefs in libavcodec.a(lpc.o)
_rc_2pass2_before in libxvidcore.a(plugin_2pass2.o)
"___ledf2", referenced from:
_qp2bits in libavcodec.a(ratecontrol.o)
_get_qscale in libavcodec.a(ratecontrol.o)
"___umodsi3", referenced from:
_vorbis_parse_setup_hdr_codebooks in libavcodec.a(vorbis_dec.o)
_vorbis_parse_setup_hdr_codebooks in libavcodec.a(vorbis_dec.o)
For running the code, these are the configuration settings:
Active architecture: x86_64
Architecture in project setting: Standard (32/64_bit universal)
Mac OS X version: 10.6.3
Xcode version: 3.2.3
Also, the same code is building and running successfully with the same settings on my other system, a Mac Mini.
If anyone has any idea what I am missing then please help. Thanks.
Read the error message carefully (emphasis mine):
ld: warning: in /Developer/SDKs/MacOSX10.6.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.2.1/libgcc.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
Looks like you're mixing PowerPC and Intel libraries somehow. You're compiling for x86_64 but you're picking up a libgcc.a for PowerPC.
Those symbols with all the leading underscores are probably supposed to come from libgcc.a but you're not linking the x86_64 version of libgcc.a so they're missing in action and chaos ensues. Sounds like something in your xcode configuration is confused.

Resources