Parsing data using QJson on mac - macos

I am working on Qt project. I have installed QJson successfully. And have used parser to parse the data.My code get compiled successfully but at run time it is giving me following error:
dyld: Library not loaded: libqjson.0.dylib
Referenced from: /Users/sanjay/untitled1-build-desktop-Qt_4_8_3_in_PATH_System_Debug/untitled1.app/Contents/MacOS/untitled1
Reason: image not found
I have added library as external library in Qt creater. It added following code to my .pro file:
macx: LIBS += -L$$PWD/../build/_preferred_path_/lib/ -lqjson
INCLUDEPATH += $$PWD/../build/_preferred_path_/include/qjson
DEPENDPATH += $$PWD/../build/_preferred_path_/include/qjson
Could anybody tell me please What am I doing wrong?

Make sure the library is located with your application's app file. Give full path names like LIBS += "lib/libqjson.dylib"
I used the above directive and it worked for me.

If your application compiles successfully then it means that project configuration defined in pro file is correct (including LIBS configuration).
In this case your application fails on runtime, so that means means that libqjson.0.dylib could not be found in library path. First check how json library is linked with your library using otool tool (http://tech-queries.blogspot.com/2011/04/dynamic-library-dependency-on-mac-os-x.html). This tool will help you to detect the problem, after detection you may:
copy libqjson.0.dylib in appropriate location
correct link using install_name_tool tool http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html
relinking of library step may be set as post build step in in pro file. Here is example:
macx {
QMAKE_POST_LINK = install_name_tool -change libqjson.0.dylib #loader_path/relative_path_to_library/libqjson.0.dylib your_binary_file

In Terminal, type this:
otool -L /Users/sanjay/untitled1-build-desktop-Qt_4_8_3_in_PATH_System_Debug/untitled1.app/Contents/MacOS/untitled1
It will tell you where each of the dependent libraries is expected to be.

Related

Xcode Library not found for -lavutil.57.28.100

I try to make macOS GUI application with ffmpeg.
On project settings -> General -> Frameworks,Libraries..., I added the ffmpeg lib files
/opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib/libavutil.57.28.100.dylib.
I also add lib search path of /opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib
I still get error : Library not found for -lavutil.57.58.100.
I like to get more detail about error.
I think these possibility
not valid arm64 format.
linker expect x64 and arm64 binary. But the file has arm64 only.
Dependency of dylib is missing.
If someone knows solution or detail about this error, please let me know.
That file exist and valid arm64 Mach-O file.
file libavutil.57.28.100.dylib
libavutil.57.28.100.dylib: Mach-O 64-bit dynamically linked shared library arm64
Some tips that will help you to troubleshoot this issue.
Firstly, lldb expects an arm64 version of the lib if your main executable's architecture is arm64, a fat-universal version of the lib if your main executable's architecture is fat-universal.
So please check the main executable's architecture inside YOURAPP.app/Contents/MacOS. I'm taking IINA video player as an example:
lipo -i /Applications/IINA.app/Contents/MacOS/IINA
Secondly, it's not good to refer to a brew version of the binary. If the library's version on another machine mismatches with yours, your app will crash. It's ok that you copy the dylib file and copy it into your Xcode project. Then you can add the dylib file to the Frameworks, libraries, and Embedded Content section in Xcode. The below image shows an example of integrating ffmpeg libs into your project.
Alternatively, the ffmpeg-kit package is your friend. I have a simple showcase for you: Github
Finally, if you insist on using the brew version, please disable checking on code-signing for external libs: Project Settings > Signing & Capabilities > Hardened Runtime > Runtime Exceptions > Diable Library Validation
Xcode does not add library search path.
I add -L/opt/homebrew/Cellar/ffmpeg/5.1-with-options_2/lib on "Other Linker Flags"

Setting Xcode linker up correctly: library not found, but in "Link Binary With Libraries" list

I have a issue with dependencies in my dylibs.
I currently get the follwing error message:
dyld: Library not loaded: /opt/local/lib/libgvc.6.dylib
Referenced from: /Users/klauskneupner/Library/Developer/Xcode/DerivedData/Visual_Thinking-bvgfcqjwnobabodenabpggrwnoet/Build/Products/Debug/Visual Thinking.app/Contents/Frameworks/libgvplugin_dot_layout.6.dylib
Reason: image not found
The funny part is that I have that library (libgvc.6) in the list of dependencies.
But in this case, the libgvc.6 is in a project directory and not in /opt/local/lib.
What do I need to do? Many thanks in advance!
At build time the static linker on OS X, ld, writes the shared library identifier of each library that your application links against in to the application binary. At run time the dynamic linker, dyld, attempts to load each shared library from the paths specified in the application binary. You can see this information using otool -L YourApp.app/Contents/MacOS/YourApp.
The reference to /opt/local/lib/libgvc.6.dylib in your crash output indicates that is the shared library identifier of libgvc.6.dylib in your project. To include the library in your .app bundle in a way that your application will use it rather than looking in /opt/local/lib you need to:
Change the shared library identifier of libgvc.6.dylib so that dyld will look for the binary within your application bundle. This is typically done by running install_name_tool -id #rpath/libgvc.6.dylib libgvc.6.dylib. The #rpath placeholder tells dyld to try substituting each of the entries in the runpath search path of the binary that is loading the library. By default your app bundle's Frameworks directory is on this search path.
Update any existing prebuilt libraries that link to libgvc.6.dylib to refer to it via the new name (the change made in step 1 only takes effect when a new binary is built against the library, so it may not be necessary if it is only prebuilt libraries that link against it). You can use install_name_tool -change /opt/local/lib/libgvc.6.dylib #rpath/libgvc.6.dylib path/to/other.dylib to update these other libraries. Your crash output shows that libgvplugin_dot_layout.6.dylib is one such library that would need updated. It may not be the only one.
Ensure that your modified libraries are being copied in to the Frameworks subdirectory in your application bundle. This is typically done using a Copy Files build phase in your Xcode project.

How to use SDL2 with Qt Creator - Windows

I was struggling with using SDL2 and Qt Creator and found some threads here on SO that were mostly helpful but nothing that put it all together for SDL2 and Qt Creator on Windows 10. The main issue was that I could not use the console for I/O at the same time as SDL2 and following the other recommendations, a number of different things went wrong.
There were two keys:
Which SDL2.dll file to use and which directory to place it.
Some said use the SDL2.dll file download from the SDL website. Others said put this file in the main project directory, which did not work for me. What worked for me was first doing a build of my project (which failed) but creates a "build-..." directory. Then, taking the SDL2.dll file from installDir\SDL2-2.0.5\i686-w64-mingw32\bin and placing it in the "build-..." directory.
In the project.pro file, adding manually:
INCLUDEPATH += installDir/SDL2-2.0.5/i686-w64-mingw32/include
LIBS += -L installDir/SDL2-2.0.5/i686-w64-mingw32/lib -lmingw32 -mwindows -mconsole -lSDL2main -lSDL2
CXXFLAGS = -std=c++11
To be honest, I don't know if all of the calls in LIBS are needed, but it's now working perfectly for me and I thought I'd share some knowledge.
Where to put the DLL
The dll, is required to be in a directory which match one of the following rules:
Is part of the $PATH$ environment variable
Is in the same directory than the executable
Is in a directory which is actively specified in your code and loaded "manually".
In my case, I just moved those DLL to my /bin folder.
Libs and includes
Includes are required for the compiler, for this purpose, both of the following possibilities match:
Copy the SDL includes in the compiler include directory.
Add the include path to the project using INCLUDEPATH as explained by #launchpadmcquack.
Libs are required by the linker, for this purpose, both of the following possibilities match:
Copy the SDL libs in the compiler lib directory.
Add the lib to the project using LIBS as explained in the question.
Considering the library list, SDL2 is required, others depends on you specific projects. E.g. In my case I do not link any of the mingw32, mwindows or mconsole.
Additional note: You may specify C++11 with the CONFIG parameter:
CONFIG *= c++11

Problems compiling with libraries

I am trying to compile some C++ code which uses the CGAL library on OS X Lion. I downloaded and installed on some directory the CGAL library. Then, when I try to compile the code, using "make";
triangulation.h:18:64: error: CGAL/Exact_predicates_inexact_constructions_kernel.h: No such file or directory
which means it does not find the CGAL lib. I look at the Makefile, and I see that it compiles using the flag
-lCGAL
Wondering how to solve this, I guess I could pass the information about the placement of my compiled library to this variable, but I do not how. I tried with export and so on but it does not recognize it, any hints?
The error message doesn't mean the library isn't found; it means a header file isn't found. The -lCGAL switch does indeed refer to the library. You're going to need a -IXXXXX switch added on to CFLAGS, where XXXXX is the path to the directory containing the CGAL directory which in turn contains Exact_predicates_inexact_constructions_kernel.h .

Why doesn't Xcode recognize my LIBRARY_SEARCH_PATHS?

I've set LIBRARY_SEARCH_PATHS to /opt/local/lib, and verified that the library in question is there (I'm linking to GLEW):
$ls /opt/local/lib
libGLEW.1.5.1.dylib libfreetype.a libz.a
libGLEW.1.5.dylib libfreetype.dylib libz.dylib
libGLEW.a libfreetype.la pkgconfig
libGLEW.dylib libz.1.2.3.dylib
libfreetype.6.dylib libz.1.dylib
but Xcode gives me the linker error
library not found for -lGLEW
I'm generating the Xcode project with CMake, so I don't want to explicitly modify the Xcode project (if someone suggests adding it as a framework, or something like that). Xcode recognizes USER_HEADER_SEARCH_PATHS fine (as in this question); why doesn't it work here?
Perhaps adding something like this to your CMakeLists.txt?
find_library(GLEW_LIB GLEW /opt/local/lib)
if(NOT ${GLEW_LIB})
message(FATAL_ERROR "Could not find GLEW")
endif()
target_link_libraries(myprogram ${GLEW_LIB} ...)
Where myprogram is the name of the target executable that needs to link with the library. You would replace the ... with the other libraries you are using on that executable.
This way CMake would handle the library path details for you.
Xcode works on potentially multiple SDK's, so whenever your define these kinds of things (like HEADER_SEARCH_PATHS or LIBRARY_SEARCH_PATHS) the current SDK root is prepended to the actual path that's getting passed to the linker.
So, one way to make this work would be to add your directory to the SDK. For example, assuming you're building with the Mac OS X 10.5 sdk, you could add your opt dir:
ln -s /opt /Developer/SDKs/MacOSX10.5.sdk/opt
Your library would now be found on your system.
If you don't want to do this, then you will have to look at CMake and find out how to get it to generate a library requirement for your actual library (I don't know anything about CMake, so I can't help you there). This is also why you see a difference between USER_HEADER_SEARCH_PATHS and HEADER_SEARCH_PATHS re your other question.
As another option, you could also specify this path with the OTHER_LDFLAGS build variable:
OTHER_LDFLAGS=-L/opt/local/lib
This would cause the linker to search /opt/local/lib as well as its standard paths and wouldn't require you to generate a different project file.

Resources