OpenGL Link Error for GLFW DDS Load function - c++

I have been working my way through the OpenGL-tutorial.org tutorial series. All has been working fine, however I have not been able to get Tutorial 5 to work in my playground executable, though it does work when run from the example tutorial 5 executable. This is true even when I copy and paste the example code over.
I receive the following errors:
Undefined symbols for architecture x86_64:
"loadDDS(char const*)", referenced from:
_main in playground.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Below is the link log:
Ld playground/playground normal x86_64
cd /Users/RufusVijayaratnam/rufus/Coding/ogl-master
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos10.15 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground -F/Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground -filelist /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground_lto.o -Xlinker -no_deduplicate -Wl,-search_paths_first -Wl,-headerpad_max_install_names -framework OpenGL -framework OpenGL /Users/RufusVijayaratnam/rufus/Coding/OpenGL/external/glfw-3.1.2/src/Debug/libglfw3.a /Users/RufusVijayaratnam/rufus/Coding/OpenGL/external/Debug/libGLEW_1130.a -framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation -framework CoreVideo -Xlinker -dependency_info -Xlinker /Users/RufusVijayaratnam/rufus/Coding/OpenGL/Tutorials.build/Debug/playground.build/Objects-normal/x86_64/playground_dependency_info.dat -o /Users/RufusVijayaratnam/rufus/Coding/ogl-master/playground/playground
So the error appears to be that when the function loadDDS() is called that it is not found. I am unsure as to why this is. The function is declared in texture.ccp which is in a folder (called 'common'), along with texture.hpp. texture.hpp has the code below:
#ifndef TEXTURE_HPP
#define TEXTURE_HPP
// Load a .DDS file using GLFW's own loader
GLuint loadDDS(const char * imagepath);
#endif
In playground.cpp there is:
include<texture.hpp>
Why can't loadDDS() be found, even though I have set the working directory of the playground function to the same as that for Tutorial 5, and the code in playground.ccp and 'tutorial05.ccp' is exactly the same?

for the playground executable (doesn't work)
# User playground add_executable(playground
playground/playground.cpp
common/shader.cpp
common/shader.hpp )
and finally for tutorial 5 (does work)
# Tutorial 5
add_executable(tutorial05_textured_cube
tutorial05_textured_cube/tutorial05.cpp
common/shader.cpp
common/shader.hpp
common/texture.cpp
common/texture.hpp
So I'm making the educated guess that loadDDS() is implemented in texture.cpp, and since you did not add this file, it won't be compiled, and the resulting object file won't be linked, and the symbol will just not be found.

Related

iOS Framework: image not found

When trying to embed a shared Framework generated from CMake into an Xcode iOS app, I encounter the following issue:
dyld: Library not loaded: /Users/jones/Documents/project/build/ios/foo.framework/foo
Referenced from: /var/Containers/Bundle/Application//myapp.app/myapp
Reason: image not found
It seems like it has an incorrect "dylib id", but I am not sure what that means exactly. Note that my framework appears in the "Frameworks" folder of the app (the built "Product" that is installed on the phone).
Checking my app with otool -L, I see:
myapp:
/Users/name/Documents/project/build/ios/foo.framework/foo
/System/Library/Frameworks/Foundation.framework/Foundation
/usr/lib/libobjc.A.dylib
...
Which seems to show that the path to my framework is wrong in the app. But I can't seem to change it from Xcode.
On the Apple dev forum, somebody mentions changing DYLIB_INSTALL_NAME_BASE to #rpath from Build Settings -> Dynamic Library Install Name Base, but it doesn't solve my problem.
The linker log coming from Xcode looks like so (maybe easier to read here:
Ld /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos/myapp.app/myapp normal arm64
cd /Users/jones/Documents/project/ios-playground/myapp
export IPHONEOS_DEPLOYMENT_TARGET=11.2
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk -L/Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos -F/Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos -F/Users/jones/Documents/project/ios-playground/myapp -F/Users/jones/Documents/project/ios-playground/myapp/Frameworks -filelist /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp.LinkFileList -Xlinker -rpath -Xlinker #executable_path/Frameworks -miphoneos-version-min=11.2 -dead_strip -Xlinker -object_path_lto -Xlinker /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fembed-bitcode-marker -stdlib=libc++ -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Xlinker -add_ast_path -Xlinker /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp.swiftmodule -framework foo -Xlinker -dependency_info -Xlinker /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Intermediates.noindex/myapp.build/Debug-iphoneos/myapp.build/Objects-normal/arm64/myapp_dependency_info.dat -o /Users/jones/Library/Developer/Xcode/DerivedData/myapp-gngqigiisiapqjflqkjjadvdbneu/Build/Products/Debug-iphoneos/myapp.app/myapp
How can I fix this?
There is actually a way to set the "install_name_dir" in CMake:
set_target_properties(dynamicFramework PROPERTIES
...
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_NAME_DIR #rpath
)

xcode c++ project with lua lib got link error

First, I create a c++ console project.
Then, I download the lua5.2.0 from lua.org, then make the lib use [make macosx test] and got the liblua.a.
Finally, I import the lua src into project and drag the liblua.a in project, write some demo code and compile,but get the link error, I confirm there has no grammar error.
Ld /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug/LuaAdapter normal x86_64
cd /Users/luocaixin/Desktop/xcodeWS1/LuaAdapter
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug -L/Users/luocaixin/Desktop/xcodeWS1/LuaAdapter/Lua.5.2.0/src -F/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug -filelist /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/LuaAdapter.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -llua -Xlinker -dependency_info -Xlinker /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/LuaAdapter_dependency_info.dat -o /Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Products/Debug/LuaAdapter
duplicate symbol _main in:
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/lua.o
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/luac.o
duplicate symbol _main in:
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/lua.o
/Users/luocaixin/Library/Developer/Xcode/DerivedData/LuaAdapter-dwqvzxkkhfmcsneiftgqstjfemts/Build/Intermediates/LuaAdapter.build/Debug/LuaAdapter.build/Objects-normal/x86_64/main.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I want to know what cause this error and how to import lua in xcode c++
project correctly.
Did you read the error? It's telling you what's wrong: you have more than one main function. You've included two object files that contain a main function (lua, luac) and probably have one in your test app, too. You need to leave those files out of your project. They are the reference command line interpreter and compiler, respectively. You don't include them if you're embedding Lua as a library.

Linker error with GLFW on OS 10.10

I'm trying to compile the following
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
return 0;
}
just to verify that my GLFW installation is working. I use the terminal with
clang++ -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo -I/opt/local/include/ test.c
but I receive a linker error for the glfwInit function:
Undefined symbols for architecture x86_64:
"_glfwInit", referenced from:
_main in test-d8c21e.o
ld: symbol(s) not found for architecture x86_64
I have installed glfw with sudo port install glfw and followed every possible tutorial I've found. I can verify that the libglfw.dylib file can be found at /opt/local/lib/ as (I think) it should.
Any suggestions?
You need to link with GLFW[3] as well, e.g., add:
-L/opt/local/lib -lglfw3
If you have the pkgconfig port installed, you can also take advantage of that with:
clang `pkg-config glfw3 --cflags` test.c -o test \
`pkg-config glfw3 --static --libs`
You may not need the --static flag if you have: libglfw3.dylib, as opposed to using: libglfw3.a, but it doesn't hurt.
If you are using Xcode, you must add the libglfw3.a library when linking binaries.
Heres the trick
Show hidden folders. Paste this into terminal: defaults write com.apple.finder AppleShowAllFiles YES
Relaunch a finder window and navigate to Macintosh HD\usr
Drag the usr folder to the "Favorites" side in the terminal
In xcode, click the add "+" to link binaries, then click "Add Other"
navigate to the libglfw3.a and add it!
If it still does not work, here are some instructions that helped me.
https://engineering-game-dev.com/2013/08/14/glfw-compiling-source-and-creating-an-xcode-project/comment-page-1/#comment-1400

Can't build PortAudio for i386 to make it play nice with NI's DAQmxBase

I'm trying to write a little C/C++ program that both acquires data from an NI USB DAQ and plays audio with PortAudio. The problem is, it appears that the NI DAQ library for Mac/Linux, DAQmxBase, has to be built under i386, and I just can't get PortAudio to build for i386.
I have tried setting CFLAGS and LDFLAGS to -arch=i386 before running ./configure --disable-mac-universal && make && make install, but the NI DAQmxBase example code still won't build when I add calls to PortAudio to it:
gcc -I../../includes -g -O2 -arch i386 acAnalogTest.c -framework nidaqmxbase -framework nidaqmxbaselv -o acAnalogTest
Undefined symbols for architecture i386:
"_Pa_Initialize", referenced from:
_main in ccf1t0bz.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [acAnalogTest] Error 1
The NI DAQmxBase Makefile looks like this:
nilibs=-framework nidaqmxbase -framework nidaqmxbaselv
includes=-I../../includes
flags= -g -O2 -arch i386
cc=gcc
ao_examples = acAnalogTest acquireNScans
......
all : $(ao_examples)
% : %.c
>---$(cc) $(includes) $(flags) $< $(nilibs) -o $#
clean :
>---rm -f $(ao_examples)
Changing the -arch flag in the DAQmxBase Makefile doesn't work:
gcc -I../../includes -g -O2 -arch x86_64 acAnalogTest.c -framework nidaqmxbase -framework nidaqmxbaselv -o acAnalogTest
In file included from acAnalogTest.c:1:
../../includes/NIDAQmxBase.h:104: warning: division by zero
../../includes/NIDAQmxBase.h:104: error: enumerator value for ‘assert_line_104’ is not an integer constant
../../includes/NIDAQmxBase.h:105: warning: division by zero
../../includes/NIDAQmxBase.h:105: error: enumerator value for ‘assert_line_105’ is not an integer constant
make: *** [acAnalogTest] Error 1
I assume this is because DAQmxBase is written with i386 data types in mind. The lines the above error references from NIDAQmxBase.h are:
NIStaticAssert(sizeof(long) == 4, "Error: This platform is unsupported because long is not 4 bytes.");
NIStaticAssert(sizeof(int) == sizeof(long), "Error: This platform is unsupported because int is not the same size as long.");
I can build some of the normal PortAudio examples on their own just fine, but I want to put PortAudio and DAQmxBase in the same program together and have them get along. There must be a way to build PortAudio so that it works with DAQmxBase, no?
Thanks!
DAQmx Base versions 14.0 and 15.0 support 64-bit applications, so you should now be able to upgrade the driver and try again.
DAQmx Base 15.0 for Mac

Apple Mach-O Linker Error - duplicate symbols

I'm having a little trouble with an app I'm making. I researched this a bit and looked at other posts, but the fixes that they proposed don't work for me. I am running all the latest softwares.
It says:
3 duplicate symbols for architecture i386
Linker command failed with exit code 1 ( use -v to see invocation)
Ld
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator/People\
Bingo.app/People\ Bingo normal i386
cd "/Users/RileyLloyd/Documents/Xcode/People Bingo"
setenv IPHONEOS_DEPLOYMENT_TARGET 7.0
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk
-L/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator
-F/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator
-filelist /Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People\
Bingo.build/Debug-iphonesimulator/People\
Bingo.build/Objects-normal/i386/People\ Bingo.LinkFileList -Xlinker
-objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.0 -framework CoreData -framework CoreGraphics -framework UIKit -framework
Foundation -Xlinker -dependency_info -Xlinker
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People\
Bingo.build/Debug-iphonesimulator/People\
Bingo.build/Objects-normal/i386/People\ Bingo_dependency_info.dat -o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Products/Debug-iphonesimulator/People\
Bingo.app/People\ Bingo
duplicate symbol _OBJC_IVAR_$_CollectionViewController._cellArray in:
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/ViewController.o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/CollectionViewController.o duplicate
symbol _OBJC_CLASS_$_CollectionViewController in:
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/ViewController.o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/CollectionViewController.o duplicate
symbol _OBJC_METACLASS_$_CollectionViewController in:
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/ViewController.o
/Users/RileyLloyd/Library/Developer/Xcode/DerivedData/People_Bingo-eqtneohyjbwwpxclkkhkbtkcddye/Build/Intermediates/People
Bingo.build/Debug-iphonesimulator/People
Bingo.build/Objects-normal/i386/CollectionViewController.o ld: 3
duplicate symbols for architecture i386 clang: error: linker command
failed with exit code 1 (use -v to see invocation)
Two modules in your application (ViewController and CollectionViewController) have provided an implementation of class CollectionViewController. The three duplication symbols are class metadata.
There are a number of ways you might have done this:
You have two modules declaring the same class. Perhaps one is vestigial?
The #implementation CollectionViewController appears in a .h file that is included in both CollectionViewController.m and ViewController.m - or you included a .m file somewhere.