Android NDK with static library: linker throws 'undefined reference' all the time - c++

First, I want to say that I've tried all other solutions on SO and the rest of the Internet.
My goal is to build dlib for android as a static library and create shared object as a wrap for JNI.
First part is compiling dlib as a static library. Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := dlib
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/entropy_encoder/entropy_encoder_kernel_2.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/entropy_encoder/entropy_encoder_kernel_1.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/all/source.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/gui_widgets/drawable.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/gui_widgets/widgets.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/gui_widgets/base_widgets.cpp
... cut many src files for simplicity.
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/threads/thread_pool_extension.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/misc_api/misc_api_kernel_1.cpp
LOCAL_SRC_FILES += $(LOCAL_PATH)/../dlib/misc_api/misc_api_kernel_2.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
include $(BUILD_STATIC_LIBRARY)
and Application.mk:
NDK_TOOLCHAIN_VERSION := clang
APP_ABI := armeabi-v7a x86
APP_CPPFLAGS := -std=c++11 -frtti -fexceptions -Os
APP_PLATFORM := android-15
APP_STL := c++_static
#APP_CFLAGS+=-DDLIB_NO_GUI_SUPPORT=on
#APP_CFLAGS+=-DDLIB_PNG_SUPPORT=off
APP_CFLAGS+=-DDLIB_JPEG_SUPPORT=on
APP_CFLAGS+=-DDLIB_JPEG_STATIC=on
###
ANDROID_NATIVE_API_LEVEL = 15
ANDROID_NDK_HOST_X64 = true
ANDROID_SDK_TARGET = 15
This works fine. I get my static library (which is 8 times bigger than when compiled with system gcc).
Next I'm trying to create wrap for JNI. My mod.cpp:
#include <jni.h>
#include <string>
#include "dlib/image_processing/frontal_face_detector.h"
extern "C"
JNIEXPORT jstring JNICALL
Java_com_cake_appa_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();
return env->NewStringUTF(hello.c_str());
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := dlib
LOCAL_SRC_FILES := $(LOCAL_PATH)/../lib/$(TARGET_ARCH_ABI)/libdlib.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := mod
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include/
LOCAL_C_INCLUDES += /usr/include/
LOCAL_SRC_FILES += $(LOCAL_PATH)/../mod.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_STATIC_LIBRARIES := dlib
LOCAL_STATIC_LIBRARY := dlib
include $(BUILD_SHARED_LIBRARY)
Application.mk:
NDK_TOOLCHAIN_VERSION := clang
APP_ABI := armeabi-v7a x86
APP_CPPFLAGS := -std=c++11 -frtti -fexceptions -Os
APP_PLATFORM := android-15
APP_STL := c++_static
And what I get when I try to build:
cake#cake-hi:/media/storage/tmp/ndk-wrap$ export NDK_PROJECT_PATH=`pwd`
cake#cake-hi:/media/storage/tmp/ndk-wrap$ /storage/android-sdk/ndk-bundle/ndk-build
[armeabi-v7a] Compile++ thumb: mod <= mod.cpp
[armeabi-v7a] SharedLibrary : libmod.so
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1958: error: undefined reference to 'XClearArea'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1959: error: undefined reference to 'XFlush'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1984: error: undefined reference to 'XVaCreateNestedList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1985: error: undefined reference to 'XSetICValues'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1986: error: undefined reference to 'XFree'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1834: error: undefined reference to 'XAllocSizeHints'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1840: error: undefined reference to 'XSetNormalHints'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1841: error: undefined reference to 'XFree'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1844: error: undefined reference to 'XResizeWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1846: error: undefined reference to 'XFlush'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1760: error: undefined reference to 'XwcTextListToTextProperty'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1761: error: undefined reference to 'XSetWMName'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1762: error: undefined reference to 'XFree'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1763: error: undefined reference to 'XFlush'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1712: error: undefined reference to 'XDestroyWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1893: error: undefined reference to 'XTranslateCoordinates'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1868: error: undefined reference to 'XMoveWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1869: error: undefined reference to 'XFlush'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1593: error: undefined reference to 'XCreateWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1620: error: undefined reference to 'XCreateFontSet'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1623: error: undefined reference to 'XVaCreateNestedList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1624: error: undefined reference to 'XCreateIC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1631: error: undefined reference to 'XFree'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1632: error: undefined reference to 'XFreeStringList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1642: error: undefined reference to 'XGetICValues'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1644: error: undefined reference to 'XSelectInput'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1652: error: undefined reference to 'XSetWMProtocols'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1668: error: undefined reference to 'XAllocSizeHints'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1674: error: undefined reference to 'XSetNormalHints'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1690: error: undefined reference to 'XDestroyIC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1692: error: undefined reference to 'XFreeFontSet'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1777: error: undefined reference to 'XMapRaised'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1804: error: undefined reference to 'XUnmapWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:639: error: undefined reference to 'XPending'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:649: error: undefined reference to 'XNextEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:653: error: undefined reference to 'XFilterEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:679: error: undefined reference to 'XInternAtom'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:685: error: undefined reference to 'XChangeProperty'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:794: error: undefined reference to 'XwcLookupString'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:797: error: undefined reference to 'XwcLookupString'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:731: error: undefined reference to 'XAllocSizeHints'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:737: error: undefined reference to 'XSetNormalHints'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:745: error: undefined reference to 'XResizeWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:752: error: undefined reference to 'XMoveWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1050: error: undefined reference to 'XCheckIfEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:697: error: undefined reference to 'XChangeProperty'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:717: error: undefined reference to 'XSendEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:804: error: undefined reference to 'XLookupString'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1018: error: undefined reference to 'XDestroyWindow'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1223: error: undefined reference to 'XInitImage'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1225: error: undefined reference to 'XCreateGC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1227: error: undefined reference to 'XPutImage'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1229: error: undefined reference to 'XFreeGC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1266: error: undefined reference to 'XGetModifierMapping'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1272: error: undefined reference to 'XkbKeycodeToKeysym'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1294: error: undefined reference to 'XFreeModifiermap'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1365: error: undefined reference to 'XSetSelectionOwner'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1423: error: undefined reference to 'XInternAtom'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1424: error: undefined reference to 'XGetSelectionOwner'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1436: error: undefined reference to 'XConvertSelection'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1441: error: undefined reference to 'XPeekIfEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1444: error: undefined reference to 'XGetWindowProperty'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1461: error: undefined reference to 'XGetWindowProperty'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1468: error: undefined reference to 'XwcTextPropertyToTextList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1473: error: undefined reference to 'XwcFreeStringList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1485: error: undefined reference to 'XwcFreeStringList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:1934: error: undefined reference to 'XScreenNumberOfScreen'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:334: error: undefined reference to 'XOpenDisplay'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:337: error: undefined reference to 'XOpenDisplay'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:369: error: undefined reference to 'XFreeFontSet'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:371: error: undefined reference to 'XCreateFontSet'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:376: error: undefined reference to 'XExtentsOfFontSet'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:379: error: undefined reference to 'XFreeStringList'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:322: error: undefined reference to 'XwcTextExtents'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:388: error: undefined reference to 'XFreeGC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:389: error: undefined reference to 'XFreePixmap'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:393: error: undefined reference to 'XDefaultDepth'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:393: error: undefined reference to 'XCreatePixmap'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:394: error: undefined reference to 'XCreateGC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:398: error: undefined reference to 'XSetForeground'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:399: error: undefined reference to 'XSetBackground'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:400: error: undefined reference to 'XFillRectangle'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:401: error: undefined reference to 'XSetForeground'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:328: error: undefined reference to 'XwcDrawString'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:405: error: undefined reference to 'XGetImage'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:313: error: undefined reference to 'XAllocColor'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:435: error: undefined reference to 'XQueryColor'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:449: error: undefined reference to 'XFreeGC'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:450: error: undefined reference to 'XFreeFontSet'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:451: error: undefined reference to 'XFreePixmap'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_widgets/nativefont.h:452: error: undefined reference to 'XCloseDisplay'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:148: error: undefined reference to 'XPutBackEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:153: error: undefined reference to 'XSendEvent'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:160: error: undefined reference to 'XCloseIM'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:163: error: undefined reference to 'XCloseDisplay'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:191: error: undefined reference to 'XInitThreads'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:203: error: undefined reference to 'XOpenDisplay'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:208: error: undefined reference to 'XOpenDisplay'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:225: error: undefined reference to 'XInternAtom'
/media/storage/tmp/ndk-dlib/jni/../dlib/all/../gui_core/gui_core_kernel_2.cpp:272: error: undefined reference to 'XCreateWindow'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
/media/storage/android-sdk/ndk-bundle/build/core/build-binary.mk:677: recipe for target '/media/storage/tmp/ndk-wrap/obj/local/armeabi-v7a/libmod.so' failed
make: *** [/media/storage/tmp/ndk-wrap/obj/local/armeabi-v7a/libmod.so] Error 1
Linker says it can't find X libraries. I guess, my system package libx11-dev:i386 won't do anything. Tried LOCAL_ALLOW_UNDEFINED_SYMBOLS := true which results in endless build which eats all system memory (6 GiB process).
Same thing happens to OpenCV, but undefined references are with something else.
I'm on Debian 9.3 x86_64.

LOCAL_C_INCLUDES += /usr/include/
Don't do this; these header files are not compatible with Android. Android does not use glibc.
I guess, my system package libx11-dev:i386 won't do anything.
No, it won't, but you do need to get your dependency from somewhere. You'll need to build that library for Android and include it (or rewrite your code to not use that library).

Related

chromiumOS emerge undefined reference to `std::__1::mutex::unlock()'

I'm writing an ebuild file which used on chromiumOS.
But when i try to compile my code, i found that i can't compile my program by "emerge xxx". It work normal when i use make directly.
I get the following error lines:
smiTransfer.o: In function `lock_guard':
/usr/bin/../include/c++/v1/__mutex_base:91: undefined reference to `std::__1::mutex::lock()'
smiTransfer.o: In function `threadsafe_queue<_RECT_IN_ENCODE_Q>::push(_RECT_IN_ENCODE_Q)':
/var/tmp/portage/app-misc/test-9999/work/test-9999/./ThreadSafeQueue.hpp:35: undefined reference to `std::__1::condition_variable::notify_one()'
smiTransfer.o: In function `~lock_guard':
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
smiTransfer.o: In function `lock_guard':
/usr/bin/../include/c++/v1/__mutex_base:91: undefined reference to `std::__1::mutex::lock()'
smiTransfer.o: In function `~lock_guard':
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
smiTransfer.o: In function `lock_guard':
/usr/bin/../include/c++/v1/__mutex_base:91: undefined reference to `std::__1::mutex::lock()'
smiTransfer.o: In function `~lock_guard':
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
/usr/bin/../include/c++/v1/__mutex_base:97: undefined reference to `std::__1::mutex::unlock()'
...
collect2: error: ld returned 1 exit status
make: *** [Makefile:43: x64/test] Error 1
* ERROR: app-misc/test-9999::chromiumos failed (compile phase):
* emake failed
*
And this is my MAKEFILE:
...
LABRARYS := -lusb-1.0
CC := g++
CFLAGS += -g -Wall -O2
CXXFLAGS := -std=c++11
CPPFLAGS := $(CFLAGS)
CPPFLAGS += $(addprefix -I,$(INCLUDES))
CPPFLAGS += -MMD
...
$(EXECUTABLE) : $(OBJS)
$(CC) -o $(EXECUTABLE) $(OBJS) -L$(LIBSDIR) $(LABRARYS) -lpthread
Thank you.

Simple linking test to MKL libraries fails

I wanted to test my MKL installation by compiling a simple program with the library:
#include <iostream>
#include <mkl.h>
int main(void)
{
std::cout << "Hello World\n";
return 0;
}
Now by using the MKL Link Line Advisor, I get the following compilation line:
g++ -DMKL_ILP64 -m64 -I${MKLROOT}/include test.cpp -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -o test
with using GCC-6.3.0 and MKLROOT set to the correct path. But when compiling, I get
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'fopen'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'fflush'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'free'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_intel_ilp64.so: error: undefined reference to 'exit'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_intel_ilp64.so: error: undefined reference to 'memset'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'strcasecmp'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'fclose'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'syscall'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'strtol'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'malloc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'strcmp'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'calloc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'getenv'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'fwrite'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to '__ctype_b_loc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'realloc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'vfprintf'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'ceil'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'gettimeofday'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strtoul'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'fopen64'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strtod'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'stdout'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'sched_yield'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'mmap'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'fread'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'stderr'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'mprotect'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'qsort'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'munmap'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'getuid'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'vsnprintf'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strchr'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'isspace'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strdup'
Is my MKL-installation broken? Or did I forget something else?
When removing the option -ldl, it works, but I have no explanation, why.
Could you try this?
-L${MKLROOT}/lib/intel64 Wl,--no-as-needed -lmkl_rt -lpthread -lm -ldl

How to fix undefined reference to v8 error?

I'm trying to configure and build a sample of node.js addon. The sample was taken from node.js documentation and the source code can be found here
https://github.com/nodejs/node-addon-examples/tree/master/8_passing_wrapped/node_0.12
When I try to compile this in CLion (on Ubuntu 14.04) or when I use node-gyp to build it I've got some errors:
/home/smorzhov/Documents/clion-2016.1/bin/cmake/bin/cmake --build /home/smorzhov/.CLion2016.1/system/cmake/generated/test4-94ee4803/94ee4803/Debug --target all -- -j 4
[ 25%] Linking CXX executable test4
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::Init(v8::Isolate*)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:26: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&), v8::Local<v8::Value>, v8::Local<v8::Signature>, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:27: undefined reference to `v8::FunctionTemplate::SetClassName(v8::Local<v8::String>)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::FunctionTemplate::InstanceTemplate()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:28: undefined reference to `v8::ObjectTemplate::SetInternalFieldCount(int)'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `v8::FunctionTemplate::GetFunction()'
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:30: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Function>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `Reset<v8::Function>':
/usr/include/node/v8.h:7235: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:38: undefined reference to `v8::Value::NumberValue() const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::PersistentBase<v8::Function> const&)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::New(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:47: undefined reference to `v8::Function::NewInstance(int, v8::Local<v8::Value>*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::PersistentBase<v8::Function> const&)':
/usr/include/node/v8.h:7124: undefined reference to `demo::MyObject::constructor'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Function>::New(v8::Isolate*, v8::Function*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `demo::MyObject::NewInstance(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/myobject.cpp:57: undefined reference to `v8::Function::NewInstance(int, v8::Local<v8::Value>*) const'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak<void>':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::Wrap(v8::Local<v8::Object>)':
/usr/include/node/node_object_wrap.h:56: undefined reference to `v8::Object::InternalFieldCount()'
/usr/include/node/node_object_wrap.h:57: undefined reference to `v8::Object::SetAlignedPointerInInternalField(int, void*)'
/usr/include/node/node_object_wrap.h:58: undefined reference to `v8::Isolate::GetCurrent()'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7176: undefined reference to `v8::V8::GlobalizeReference(v8::internal::Isolate*, v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `SetWeak<v8::Object, node::ObjectWrap>':
/usr/include/node/v8.h:7257: undefined reference to `v8::V8::MakeWeak(v8::internal::Object**, void*, void (*)(v8::WeakCallbackData<v8::Value, void> const&))'
CMakeFiles/test4.dir/myobject.cpp.o: In function `ClearWeak<void>':
/usr/include/node/v8.h:7298: undefined reference to `v8::V8::ClearWeak(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData<v8::Object, node::ObjectWrap> const&)':
/usr/include/node/node_object_wrap.h:101: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::Local<v8::Object>::New(v8::Isolate*, v8::Object*)':
/usr/include/node/v8.h:7134: undefined reference to `v8::HandleScope::CreateHandle(v8::internal::Isolate*, v8::internal::Object*)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `v8::PersistentBase<v8::Object>::Reset()':
/usr/include/node/v8.h:7224: undefined reference to `v8::V8::DisposeGlobal(v8::internal::Object**)'
CMakeFiles/test4.dir/myobject.cpp.o: In function `node::ObjectWrap::WeakCallback(v8::WeakCallbackData<v8::Object, node::ObjectWrap> const&)':
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node_object_wrap.h:108: undefined reference to `v8::HandleScope::~HandleScope()'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::Add(v8::FunctionCallbackInfo<v8::Value> const&)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:27: undefined reference to `v8::Number::New(v8::Isolate*, double)'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::InitAll(v8::Local<v8::Object>)':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:31: undefined reference to `v8::Object::GetIsolate()'
CMakeFiles/test4.dir/addon.cpp.o: In function `_register_addon':
/home/smorzhov/ClionProjects/test4/test4/addon.cpp:37: undefined reference to `node_module_register'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Value::ToObject() const':
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/v8.h:7778: undefined reference to `v8::Isolate::GetCurrentContext()'
/usr/include/node/v8.h:7779: undefined reference to `v8::Value::ToObject(v8::Local<v8::Context>) const'
CMakeFiles/test4.dir/addon.cpp.o: In function `demo::MyObject* node::ObjectWrap::Unwrap<demo::MyObject>(v8::Local<v8::Object>)':
/usr/include/node/node_object_wrap.h:29: undefined reference to `v8::Object::InternalFieldCount()'
CMakeFiles/test4.dir/addon.cpp.o: In function `v8::Object::GetAlignedPointerFromInternalField(int)':
/usr/include/node/v8.h:7636: undefined reference to `v8::Object::SlowGetAlignedPointerFromInternalField(int)'
CMakeFiles/test4.dir/addon.cpp.o: In function `void node::NODE_SET_METHOD<v8::Local<v8::Object> >(v8::Local<v8::Object> const&, char const*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&))':
/usr/include/node/node.h:239: undefined reference to `v8::Isolate::GetCurrent()'
/usr/include/node/node.h:240: undefined reference to `v8::HandleScope::HandleScope(v8::Isolate*)'
/usr/include/node/node.h:242: undefined reference to `v8::FunctionTemplate::New(v8::Isolate*, void (*)(v8::FunctionCallbackInfo<v8::Value> const&), v8::Local<v8::Value>, v8::Local<v8::Signature>, int)'
/usr/include/node/node.h:243: undefined reference to `v8::FunctionTemplate::GetFunction()'
/usr/include/node/node.h:244: undefined reference to `v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::String::NewStringType, int)'
/usr/include/node/node.h:245: undefined reference to `v8::Function::SetName(v8::Local<v8::String>)'
/usr/include/node/node.h:246: undefined reference to `v8::Object::Set(v8::Local<v8::Value>, v8::Local<v8::Value>)'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
/usr/include/node/node.h:246: undefined reference to `v8::HandleScope::~HandleScope()'
collect2: error: ld returned 1 exit status
make[2]: *** [test4] Error 1
make[1]: *** [CMakeFiles/test4.dir/all] Error 2
make: *** [all] Error 2
Maybe it is important, the IDE don't understand
#include node.h
and I have to change it to #include node/node.h
It seems, that compiler sees only node and v8 headers and cannot find their sources.
Can somebody help me to fix that? How to make compiler to see node and v8 sources?
PS. My CmakeLists.txt file
cmake_minimum_required(VERSION 3.3)
project(test4)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES addon.cpp main.cpp myobject.cpp myobject.h)
add_executable(test4 ${SOURCE_FILES})
If you follow the README and use node-gyp with the -v flag, you can see that compilation looks like this:
g++ '-DNODE_GYP_MODULE_NAME=addon' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/home/yannick/.node-gyp/5.9.0/include/node -I/home/yannick/.node-gyp/5.9.0/src -I/home/yannick/.node-gyp/5.9.0/deps/uv/include -I/home/yannick/.node-gyp/5.9.0/deps/v8/include -fPIC -pthread -Wall -Wextra -Wno-unused-parameter -m64 -O3 -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-rtti -fno-exceptions -std=gnu++0x -MMD -MF ./Release/.deps/Release/obj.target/addon/myobject.o.d.raw -c -o Release/obj.target/addon/myobject.o ../myobject.cc
So it's a tad more complex that just specifying a few sources : there are several include dirs to be used, that seems specific to the node version you are running, and include an external dependency (libuv)
Why don't you use the build methods suggested by the README ?

Netbeans complaining about undefined OpenGL references

I am very new to c++ and OpenGL so I am not sure 100% what I am doing yet...
So, I copied the following code from This page:
#include <GLFW/glfw3.h>
int main(void) {
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window)) {
/* Render here */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
When I run it in netbeans, I get the follow errors:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/ryan/NetBeansProjects/Test3D'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/test3d
make[2]: Entering directory `/home/ryan/NetBeansProjects/Test3D'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++ -c -g `pkg-config --cflags glfw3` `pkg-config --cflags x11` -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/test3d build/Debug/GNU-Linux-x86/main.o `pkg-config --libs glfw3` `pkg-config --libs x11`
/usr/local/lib/libglfw3.a(context.c.o): In function `parseGLVersion':
context.c:(.text+0x53): undefined reference to `glGetString'
/usr/local/lib/libglfw3.a(context.c.o): In function `_glfwRefreshContextAttribs':
context.c:(.text+0x8d3): undefined reference to `glGetIntegerv'
context.c:(.text+0x956): undefined reference to `glGetIntegerv'
context.c:(.text+0x9c9): undefined reference to `glGetIntegerv'
context.c:(.text+0xa1e): undefined reference to `glGetIntegerv'
/usr/local/lib/libglfw3.a(context.c.o): In function `glfwExtensionSupported':
context.c:(.text+0xd29): undefined reference to `glGetString'
context.c:(.text+0xd88): undefined reference to `glGetIntegerv'
/usr/local/lib/libglfw3.a(window.c.o): In function `glfwCreateWindow':
window.c:(.text+0x724): undefined reference to `glClear'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwInitGammaRamp':
x11_gamma.c:(.text+0x49): undefined reference to `XRRGetScreenResources'
x11_gamma.c:(.text+0x6a): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0x81): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformGetGammaRamp':
x11_gamma.c:(.text+0xce): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0xf1): undefined reference to `XRRGetCrtcGamma'
x11_gamma.c:(.text+0x17d): undefined reference to `XRRFreeGamma'
x11_gamma.c:(.text+0x1a5): undefined reference to `XF86VidModeGetGammaRampSize'
x11_gamma.c:(.text+0x1f3): undefined reference to `XF86VidModeGetGammaRamp'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformSetGammaRamp':
x11_gamma.c:(.text+0x231): undefined reference to `XRRAllocGamma'
x11_gamma.c:(.text+0x2cd): undefined reference to `XRRSetCrtcGamma'
x11_gamma.c:(.text+0x2d9): undefined reference to `XRRFreeGamma'
x11_gamma.c:(.text+0x321): undefined reference to `XF86VidModeSetGammaRamp'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x15f2): undefined reference to `XF86VidModeQueryExtension'
x11_init.c:(.text+0x1611): undefined reference to `XRRQueryExtension'
x11_init.c:(.text+0x163b): undefined reference to `XRRQueryVersion'
x11_init.c:(.text+0x16cf): undefined reference to `XIQueryVersion'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwSetVideoMode':
x11_monitor.c:(.text+0x176): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x19b): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x1bd): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x3c3): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x3cf): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x3db): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x3e7): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwRestoreVideoMode':
x11_monitor.c:(.text+0x432): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x457): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x4cc): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x4d8): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x4e4): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x543): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x560): undefined reference to `XRRGetOutputPrimary'
x11_monitor.c:(.text+0x5b8): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x5d3): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x642): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x65f): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x66b): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x6ff): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x70b): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x72f): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitorPos':
x11_monitor.c:(.text+0x8b3): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x8d8): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x910): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x91c): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoModes':
x11_monitor.c:(.text+0x9be): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x9e0): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0xb6d): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0xb79): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoMode':
x11_monitor.c:(.text+0xc51): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0xc76): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xccb): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xcd7): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `createWindow':
x11_window.c:(.text+0x6dc): undefined reference to `XISelectEvents'
x11_window.c:(.text+0x71e): undefined reference to `XRRSelectInput'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `processEvent':
x11_window.c:(.text+0x1784): undefined reference to `XRRUpdateConfiguration'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `getFBConfigAttrib':
glx_context.c:(.text+0x4d): undefined reference to `glXGetFBConfigAttrib'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `chooseFBConfig':
glx_context.c:(.text+0x7a): undefined reference to `glXGetClientString'
glx_context.c:(.text+0xe5): undefined reference to `glXGetFBConfigs'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `createLegacyContext':
glx_context.c:(.text+0x41f): undefined reference to `glXCreateNewContext'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwInitContextAPI':
glx_context.c:(.text+0x434): undefined reference to `pthread_key_create'
glx_context.c:(.text+0x46f): undefined reference to `glXQueryExtension'
glx_context.c:(.text+0x4aa): undefined reference to `glXQueryVersion'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwTerminateContextAPI':
glx_context.c:(.text+0x69e): undefined reference to `pthread_key_delete'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwCreateContext':
glx_context.c:(.text+0x780): undefined reference to `glXGetVisualFromFBConfig'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwDestroyContext':
glx_context.c:(.text+0xda8): undefined reference to `glXDestroyContext'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformMakeContextCurrent':
glx_context.c:(.text+0xdf4): undefined reference to `glXMakeCurrent'
glx_context.c:(.text+0xe0f): undefined reference to `glXMakeCurrent'
glx_context.c:(.text+0xe23): undefined reference to `pthread_setspecific'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformGetCurrentContext':
glx_context.c:(.text+0xe36): undefined reference to `pthread_getspecific'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformSwapBuffers':
glx_context.c:(.text+0xe61): undefined reference to `glXSwapBuffers'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformExtensionSupported':
glx_context.c:(.text+0xf04): undefined reference to `glXQueryExtensionsString'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformGetProcAddress':
glx_context.c:(.text+0xf4c): undefined reference to `glXGetProcAddressARB'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/test3d] Error 1
make[2]: Leaving directory `/home/ryan/NetBeansProjects/Test3D'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/ryan/NetBeansProjects/Test3D'
make: *** [.build-impl] Error 2
I am not sure what this means 100%, but I am assuming I don't have some packages added to the project.
However, I was able to install and run a program following thsese steps: https://stackoverflow.com/a/17772217/1778465 which links to here http://www.glfw.org/docs/3.0/quick.html, so I know that GLFW works.
Your build settings lack to specify to link with the OpenGL interface library. When compiling for
Windows → opengl32.lib → -lopengl32
X11/GLX (Linux / *BSD / *Solaris) → libGL.so -lGL
MacOS X → OpenGL Framework → -framework OpenGL

Compile error when linking against two libraries in C++

compile command:
g++ ast01.cpp -o ast01 -lglu -lglut
error:
/usr/bin/ld: error: cannot find -lglu
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glClear'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glBegin'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glColor3ub'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glEnd'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glFlush'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glClearColor'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glMatrixMode'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glLoadIdentity'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'gluOrtho2D'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glMatrixMode'
collect2: ld returned 1 exit status