On Thursday, December 19, 2019 at 11:23:41 AM UTC+13, Bruno Albuquerque wrote: > > I am trying to get a version of GoCV that works with OpenCV static > libraries. The final issue I have is that pkg-config is not really listing > all required libraries so i need to append some extra ones. Here is how my > cgo configuration looks like without the extra libraries: > > #cgo !windows pkg-config: --static opencv4 > #cgo CXXFLAGS: --std=c++11 > > This mostly works but, as I mentioned, pkg-config -static is somehow > missing some libraries and I have to add then. > > because I am dealing with static libraries, it is important that they are > all added after all the other -llibrary entries. > > I tried adding the libraries after the last #cgo statement, like this: > > #cgo !windows pkg-config: --static opencv4 > #cgo CXXFLAGS: --std=c++11 > #cgo !windows LDFLAGS: -ldc1394 -lavcodec -lavformat -lavutil -lswscale >
Are their pc file definitions for the avcodec and other dependencies? If so, can you pass them all to pkg-config? #cgo !windows pkg-config: --static opencv4 avcodec ... Other than that, I am not sure how you can get fine grained control of order when mixing pkg-config and LDFLAGS. Usually when I am static linking cgo I am 100% using CXXFLAGS/LDFLAGS and not pkg-config. Maybe they could introduce something like LINKFLAGS which is the same as LDFLAGS but appends to the end? (I got that concept from using the waf build system, which provides that setting as well). > > This correctly adds the libraries to the linker command but the libraries > are added before any other entries. i.e, here is what I get: > > TERM='dumb' g++ -I . -fPIC -m64 -pthread -fmessage-length=0 > -fdebug-prefix-map=$WORK/b031=/tmp/go-build -gno-record-gcc-switches -o > $WORK/b031/_cgo_.o $WORK/b031/_cgo_main.o $WORK/b031/_x001.o > $WORK/b031/_x002.o $WORK/b031/_x003.o $WORK/b031/_x004.o $WORK/b031/_x005.o > $WORK/b031/_x006.o $WORK/b031/_x007.o $WORK/b031/_x008.o $WORK/b031/_x009.o > $WORK/b031/_x010.o $WORK/b031/_x011.o $WORK/b031/_x012.o $WORK/b031/_x013.o > $WORK/b031/_x014.o $WORK/b031/_x015.o $WORK/b031/_x016.o $WORK/b031/_x017.o > $WORK/b031/_x018.o $WORK/b031/_x019.o $WORK/b031/_x020.o $WORK/b031/_x021.o > $WORK/b031/_x022.o $WORK/b031/_x023.o $WORK/b031/_x024.o $WORK/b031/_x025.o > -g -O2 -ldc1394 -lavcodec -lavformat -lavutil -lswscale -ldc1394 -lavcodec > -L/usr/local/lib -L/usr/local/lib/opencv4/3rdparty > -L/tmp/opencv/opencv-4.1.2/build/lib -lopencv_gapi -lopencv_stitching > -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib > -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui > -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs > -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg > -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light > -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow > -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text > -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_video > -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml > -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d > -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto > -lopencv_photo -lopencv_imgproc -lopencv_core -littnotify -llibprotobuf > -llibwebp -lIlmImf -lquirc -lippiw -lippicv -lade -lgtk-x11-2.0 > -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 > -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig > -lgthread-2.0 -ljpeg -lpng -lz -ltiff -lfreetype -lharfbuzz -ldl -lm > -lpthread -lrt > > This fails. If I simply move the libraries to the end, then it works: > > TERM='dumb' g++ -I . -fPIC -m64 -pthread -fmessage-length=0 > -fdebug-prefix-map=$WORK/b031=/tmp/go-build -gno-record-gcc-switches -o > $WORK/b031/_cgo_.o $WORK/b031/_cgo_main.o $WORK/b031/_x001.o > $WORK/b031/_x002.o $WORK/b031/_x003.o $WORK/b031/_x004.o $WORK/b031/_x005.o > $WORK/b031/_x006.o $WORK/b031/_x007.o $WORK/b031/_x008.o $WORK/b031/_x009.o > $WORK/b031/_x010.o $WORK/b031/_x011.o $WORK/b031/_x012.o $WORK/b031/_x013.o > $WORK/b031/_x014.o $WORK/b031/_x015.o $WORK/b031/_x016.o $WORK/b031/_x017.o > $WORK/b031/_x018.o $WORK/b031/_x019.o $WORK/b031/_x020.o $WORK/b031/_x021.o > $WORK/b031/_x022.o $WORK/b031/_x023.o $WORK/b031/_x024.o $WORK/b031/_x025.o > -g -O2 -L/usr/local/lib -L/usr/local/lib/opencv4/3rdparty > -L/tmp/opencv/opencv-4.1.2/build/lib -lopencv_gapi -lopencv_stitching > -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib > -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_highgui > -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs > -lopencv_img_hash -lopencv_line_descriptor -lopencv_quality -lopencv_reg > -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light > -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow > -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text > -lopencv_dnn -lopencv_plot -lopencv_videostab -lopencv_video > -lopencv_videoio -lopencv_xfeatures2d -lopencv_shape -lopencv_ml > -lopencv_ximgproc -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d > -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto > -lopencv_photo -lopencv_imgproc -lopencv_core -littnotify -llibprotobuf > -llibwebp -lIlmImf -lquirc -lippiw -lippicv -lade -lgtk-x11-2.0 > -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 > -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig > -lgthread-2.0 -ljpeg -lpng -lz -ltiff -lfreetype -lharfbuzz -ldl -lm > -lpthread -lrt -ldc1394 -lavcodec -lavformat -lavutil -lswscale -ldc1394 > -lavcodec > > Is there a way to get the behavior I need other than manually expanding > the libraries returned by pkg-config? > > Thanks in advance. > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9ddb3bfb-da36-4b71-a21d-ec58619df339%40googlegroups.com.