Why can't I link against shaderc? - c++

I have a vulkan project that is trying to use shaderc.
The library was installed under the following path (linux system):
./libraries/shaderc/build/libshaderc
Doing ls in this directory gives:
CMakeFiles shaderc_combined_shaderc_test
cmake_install.cmake shaderc_c_smoke_test
CTestTestfile.cmake shaderc_shaderc_cpp_test
libshaderc.a shaderc_shaderc_private_test
libshaderc_combined.a shaderc_shaderc_test
libshaderc_shared.so shaderc_shared_shaderc_cpp_test
libshaderc_shared.so.1 shaderc_shared_shaderc_private_test
shaderc_combined.ar shaderc_shared_shaderc_test
shaderc_combined_shaderc_cpp_test
The documentation provided with the library explicitly states:
If the external project does not use CMake, then the external project can instead directly use the generated libraries.
shaderc/libshaderc/include should be added to the include path, and
build/libshaderc/libshaderc_combined.a should be linked. Note that
on some platforms -lpthread should also be specified.
I attempt to link the project as follows using make:
g++ -o "../build/VulkanEngine" obj/Debug/DebugCallback.o obj/Debug/Device.o obj/Debug/log.o obj/Debug/ImageViews.o obj/Debug/Instance.o obj/Debug/Pipeline.o obj/Debug/RenderPass.o obj/Debug/Surface.o obj/Debug/SwapChain.o obj/Debug/VkExtensionsStubs.o obj/Debug/GLFW_tools.o obj/Debug/main.o -L../libraries/glfw-3.2.1/bin -L../libraries/glm/bin/glm -L../libraries/vulkansdk-linux/1.1.97.0/x86_64/lib -L../libraries/shaderc/build/libshaderc -lstdc++fs -lglfw -lglm_static-lvulkan -llibshaderc_combined.a
In particular notice the argument -L../libraries/shaderc/build/libshaderc: and the argument -llibshaderc_combined.a
As you can see the specified linking path matches the installation path (libraries/ contains all the third party libraries my project uses).
However the linker complains:
/usr/bin/ld: cannot find -llibshaderc_combined.a
collect2: error: ld returned 1 exit status
make[1]: *** [VulkanEngine.make:119: ../build/VulkanEngine] Error 1
make: *** [Makefile:30: VulkanEngine] Error 2
So it seems I messed up the path somehow, but I don;t know how.

The -lname linkage option directs the linker to search in specified
(-Ldir) and default library search directories for either of the
files libname.so (shared library) or libname.a (static library). If it finds either of them them it searches
no more directories and inputs that file to the linkage. If it finds
both of them in the same search directory then it will prefer libname.so.
So change:
-llibshaderc_combined.a
to:
-lshaderc_combined
You must also be sure that -lshaderc_combined appears in the linkage
sequence before any other library that it depends on, and after any object file or library that depends upon it, or the linkage
is liable to fail with undefined reference errors.

Related

G++ error with -lxnt flag after xlnt is installed

I am trying to install the xlnt library on Ubuntu 18. I have installed xlnt exactly as the instructions say on the repo. When I try to compile my code, the following error pops up:
/usr/bin/ld: cannot find -lxlnt
collect2: error: ld returned 1 exit status
makefile:204: recipe for target 'BOF-debug-static' failed
make: *** [BOF-debug-static] Error 1
I have been installing other libraries to get the code working, and I've noticed that the other libraries are creating .a files at /usr/local/lib along with a few other .la, and .so files. When I install xlnt, it is not creating any .a files, but does create a .so and .so.1.2 files. Not sure if that is relevant, but it's something I've noticed.
How do I make xlnt discoverable to g++ and get the -lxlnt flag to work?
The target you are building BOF-debug-static is evidently one that requests
either a fully static linkage, with the -static linkage option, or possibly one that
requests static linkage specifically of libxlnt, with a linkage option such as:
-Wl,-Bstatic -lxlnt -Wl,-Bdynamic
Since, as you observed, libxlnt by default provides only a shared/dynamic library libzlint.so ( -> libzlint.so.X.Y.Z),
and no static library libzlnt.a, the linker ignores the the shared library when
required to link -lxlnt statically and says:
/usr/bin/ld: cannot find -lxlnt
You cannot link a shared library statically.
However, if you configure the CMake build system with:
cmake -DSTATIC=ON [your previous options...]
then make will build a static library and running make install (as root) will create /usr/local/lib/libxlnt.a.

wsdlpull: linking error with g++

I'm new to programming c++ with g++ and have big problems to get wsdlpull-library to work. The version is 1.24.
I followed the installation steps from http://wsdlpull.sourceforge.net/.:
./configure --prefix=/home/jesse/Dropbox/Programmering/C++/test --disable-opt --enable-examples
make
make install
I then copied print.cpp file from the example to the "prefix"-directory. The next step would be "add the $(prefix)/include in your include path and add $(prefix)/libs and -lwsdl -lschema -lxmlpull to your LDFLAGS". The first problem is that there's no folder "libs" but "lib" and the include-folder has another folder inside named wsdlpull. Therefore I instead entered the following command:
g++ -I include/wsdlpull -L lib -lwsdl -lschema -lxmlpull -o print print.cpp
This resulted in the following error:
/usr/bin/ld: cannot find -lwsdl
/usr/bin/ld: cannot find -lschema
/usr/bin/ld: cannot find -lxmlpull
collect2: error: ld returned 1 exit status
I have no idea what this means, why does it look in /usr/bin/ld when I point to "lib"?
When you use -L lib, it means that, lib dir is available in pwd where you are doing make. Check whether you have said lib is really available or not.
To make things simple, you can give the absolute path of the lib folder.
i.e -L<path to lib>/lib. This would help the make to see the lib without any confusions.
Next, you might want to explicitly specify whether libwsdl is a static or shared library. Although this is optional.
Or, the best solution is to place the libraries in system libs location i.e /lib or /usr/lib or /use/local/lib and run ldconfig such that the linker/loader knows where the newly added libraries exists. In such case, you can simple issue -lwsdl without specifying the -L flag.
For more info, please refer ldconfig.

How to use external .h and .o files in current project with Eclipse CDT

I was given three files to test my project: Test1.cpp SignalMasker.h and SignalMasker.o when Test1.cpp includes the SignalMasker.h file and files from my project. Putting both in the source folder returns undefined references such as:
error: undefined reference to 'SignalMasker::~SignalMasker()'
I tried to use the project preferences and add the .o file to it. Under GCC C++ Linker-> Miscellaneous -> other objects. When selecting a file it inserted a new record as:
"${workspace_loc:/${ProjName}/source/SignalMasker.o}"
Building it didn't seem to resolve the issue so I added to the Linker flags the -l flag and got:
Invoking: GCC C++ Linker
g++ -l -o "uthreads" ./source/Scheduler.o ./source/SchedulerStarter.o ./source/Test1.o ./source/Thread.o ./source/main.o ./source/uthreads.o /home/tom/workspace/uthreads/source/SignalMasker.o
g++: error: uthreads: No such file or directory
make: *** [uthreads] Error 1
So I went back to other objects and replaced the automatic generated variable to:
./source/SignalMasker.o
And building gave me:
make: *** No rule to make target `source/SignalMasker.o', needed by `uthreads'. Stop.
These are all solutions I've found in SO and none seem to work including making a library and trying to include it. Please help.
EDIT: uthreads is also the name of the project.

CodeBlocks cannot find shared libraries even when search paths are setup

I have a very basic C++ project in code blocks that makes use of glfw.so and two other libraries that are compiled to .so files from another project, libHorde3D.so and libHorde3DUtils.so. The latter are placed in the project root folder, while glfw is somewhere in my /usr/lib (I think).
I have added the project folder to the linker and compiler search paths in code blocks. I have added the libHorde3D.so and libHorde3DUtils.so as well as glfw.so to the Link Libraries in the Linker Settings tab. I thought that this would be enough based on the previous similar questions here on stackoverflow.
However when I press build:
ld cannot find -lHorde3D.so
ld cannot find -lHorde3DUtils.so
ld cannot find -lglfw.so
My system is Arch Linux 64 and I am using GCC.
I also tried bopying libHorde3D.so and libHorde3DUtils.so in /usr/lib and /usr/lib64 with no success.
P.S. All search paths are copied across the Debug and Release target.
Say, if the library name is libmylibrary.so, then linker option to link against that library would look like -lmylibrary. Note that lib prefix and .so suffix are not there — they are added automatically by the linker. In your case it seems like you specified the wrong name. Try removing .so from it, that should solve the problem.
Here is a simple demonstration of how to trigger the failure by making a similar mistake:
$ echo 'int main() { return 0; }' > test.c
$ gcc -o test ./test.c -lc
$ gcc -o test ./test.c -lc.so
/usr/bin/ld: cannot find -lc.so
collect2: ld returned 1 exit status
$
The first command succeeds and the second one (with incorrect library name) fails.
You must not pass ".so". The linker options are
-lHorde3D -lHorde3DUtils -lglfw
This way the linker will search for "libHorde3D.so" etc. in the library path(s).

How do I solve these libcurl linking errors?

[Administrator#windows ~]$ g++ client.cpp -lcurl -o client.exe
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x23): undefined reference to `_imp__curl_global_init'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x5f): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x9b): undefined reference to `_imp__curl_formadd'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xa2): undefined reference to `_imp__curl_easy_init'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xc8): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xe4): undefined reference to `_imp__curl_easy_setopt'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0xf1): undefined reference to `_imp__curl_easy_perform'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x101): undefined reference to `_imp__curl_easy_cleanup'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x10e): undefined reference to `_imp__curl_formfree'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ccKXFUtC.o:client.cpp:(.text+0x11b): undefined reference to `_imp__curl_slist_free_all'
collect2: ld returned 1 exit status
I don't have this problem on linux so I don't know why this happens on windows. I googled it already and didn't find anything except mailing list archives with the same question and reply saying "google it".
I'm using mingw. I did get some linker warnings when I built libcurl but they seemed to be ssl related and I don't know if it's a big deal because it built without errors.
*** Warning: linker path does not have real file for library -lssl.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libssl and none of the candidates passed a file format test
*** using a file magic. Last file checked: /ssl/lib/libssl.a
*** Warning: linker path does not have real file for library -lcrypto.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libcrypto and none of the candidates passed a file format test
*** using a file magic. Last file checked: /ssl/lib/libcrypto.a
*** Warning: linker path does not have real file for library -lz.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libz and none of the candidates passed a file format test
*** using a file magic. Last file checked: /mingw/lib//libz.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.
*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.
I was able to avoid these curl linking errors on windows (mingw win32) by adding option -lcurl.dll. -DCURL_STATICLIB was not needed in my case.
My build has two libcurl files in mingw/lib folder: libcurl.a and libcurl.dll.a
Libtool only built a static libcurl and not a dynamic library. Your headers are looking for a dynamic libcurl. It's probably not libcurl's fault, because I can see code in the headers that supports __declspec(dllimport) and __declspec(dllexport) (that's a good sign the package author knows what's what.
Technical details: see this answer regarding libssh.
Solution: Compile with -DCURL_STATICLIB.
Was having the same issue using netbeans 7.1 with mingw. From properties, linker adding library libcurl.dll.a solved the issue for me.
This file was located under curl-7.28.1\lib.libs after I ran the mingw make.
I had similar error (with libz and libsqlite) in different projects.
It is produced by GNU libtool script.
The reason in my case was lack of some files for these libraries (.la ?) or maybe libz.dll.a variants of the libraries.
To have all necessary files for automake/autoconf build ./configure --prefix=... ; make, you'll have to build zlib, crypto and ssl with configure and make to under the same MSYS.
cmake or custom makefile builds will usually not work as dependencies for shared-library autotool build.
Another and the most simple option is to build dynamic curl with cmake ( https://github.com/bagder/curl.git )