I installed Qt 5.0.0 (qt-mac-opensource-5.0.0-clang-offline.dmg) on a Mac OS X 10.7.5 and now I'm trying to compile a "Hello World" application using Qt Creator 2.6.1.
The build process complains about a directory not found: /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib , followed by several linking errors:
clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/mkspecs/macx-clang -I. -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtGui -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtGui.framework/Versions/5/Headers -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/include/QtCore -I/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -o main.o main.cpp
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o hello_qt.app/Contents/MacOS/hello_qt main.o -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib -framework QtGui -F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib -framework QtCore -framework OpenGL -framework AGL
ld: warning: directory not found for option '-F/Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib'
Undefined symbols for architecture x86_64:
"QApplication::QApplication(int&, char**, int)", referenced from:
_main in main.o
"QLabel::QLabel(QString const&, QWidget*, QFlags<Qt::WindowType>)", referenced from:
_main in main.o
"QWidget::show()", referenced from:
_main in main.o
"QPushButton::QPushButton(QString const&, QWidget*)", referenced from:
_main in main.o
"QApplication::exec()", referenced from:
_main in main.o
"QPushButton::~QPushButton()", referenced from:
_main in main.o
"QLabel::~QLabel()", referenced from:
_main in main.o
"QApplication::~QApplication()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello_qt.app/Contents/MacOS/hello_qt] Error 1
It's important to note that the path /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/qtbase/lib is not valid because the directory qtbase doesn't exist. The working path is /Users/karlphillip/Qt5.0.0/5.0.0/clang_64/lib. I'm not referring to qtbase anywhere in my project, so this is probably being added by qmake.
As it turns out, the invalid qtbase path thing is really a Qt bug originally reported at QTBUG-28336.
The linking problem is due to my project not linking with QtWidgets, which is something we are going to have to do starting in Qt5. This is accomplished by adding the following line to your .pro file:
QT += widgets
i had the same problem and to be honest im not shure how i managed it to solve.
i think/guess i copied the needed folders from the sources into the matching 'clang_64' folders and that does the job.
soo long zai
Related
I am getting this "symbol(s) not found in architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)." Actually, these messages didn't appear until I upgraded to macOS Mojave.
The complete message I got is:
g++ -Wall -fexceptions -g -c /Users/suraj/Desktop/sfm/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/sfm obj/Debug/main.o
Undefined symbols for architecture x86_64:
"sf::CircleShape::CircleShape(float, unsigned long)", referenced from:
_main in main.o
"sf::RenderStates::Default", referenced from:
_main in main.o
"sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)",
referenced from:
_main in main.o
"sf::RenderTarget::clear(sf::Color const&)", referenced from:
_main in main.o
"sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&,
unsigned int, sf::ContextSettings const&)", referenced from:
_main in main.o
"sf::RenderWindow::~RenderWindow()", referenced from:
_main in main.o
"sf::Color::Green", referenced from:
_main in main.o
"sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned
char)", referenced from:
_main in main.o
"sf::Shape::setFillColor(sf::Color const&)", referenced from:
_main in main.o
"sf::Shape::~Shape()", referenced from:
sf::CircleShape::~CircleShape() in main.o
"sf::String::String(char const*, std::__1::locale const&)", referenced
from:
_main in main.o
"sf::Window::close()", referenced from:
_main in main.o
"sf::Window::display()", referenced from:
_main in main.o
"sf::Window::pollEvent(sf::Event&)", referenced from:
_main in main.o
"sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)",
referenced from:
_main in main.o
"sf::Window::isOpen() const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The code is:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(400, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
Please help.
Updated Answer - May 2019
It seems that the openal package is no longer in homebrew and that causes the instructions below to fail. I don't know the background behind it. Here is another approach.
You can find all the pkg-config related parts of sfml like this:
find /usr/local/Cellar/sfml -name \*pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-network.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-all.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-graphics.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-audio.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-system.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-window.pc
It seems you cannot use sfml-all nor sfml-audio in the above list, so you will need to pick which parts you want to use and grab them individually, so if you want graphics, window and system:
pkg-config --libs --cflags sfml-graphics
-I/usr/local/Cellar/sfml/2.5.1/include
-I/usr/local/opt/freetype/include/freetype2
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-graphics -lsfml-window -lsfml-system
pkg-config --libs --cflags sfml-system
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-system
pkg-config --libs --cflags sfml-window
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-window -lsfml-system
So, you would compile with:
g++ main.cpp $(pkg-config --libs --cflags sfml-window sfml-system sfml-graphics) -o main
Original Answer
If you installed sfml via homebrew, I would suggest you also install pkg-config like this:
brew install pkg-config
Then you can get the switches needed to compile with:
pkg-config --libs --cflags sfml-all
Sample Output
-I/usr/local/Cellar/sfml/2.4.2_1/include -L/usr/local/Cellar/sfml/2.4.2_1/lib -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-network -lsfml-system
So you can compile with:
g++ main.cpp $(pkg-config --libs --cflags sfml-all) -o main
I saw someone use swift code from android, using #_cdecl swift functions. I am able to compile to native using swiftc -emit-object, but when trying to link, I cant get the linker to work correctly..
I am trying to use g++ or clang(++) to compile and link a native swift object, has someone successfully done this already?
The errors I get are listed below:
Undefined symbols for architecture x86_64:
"__T0S2SBp21_builtinStringLiteral_Bw17utf8CodeUnitCountBi1_7isASCIItcfC", referenced from:
__T04main4testyyF in main.o
"__T0SSN", referenced from:
__T04main4testyyF in main.o
"__T0s27_allocateUninitializedArraySayxG_BptBwlFyp_Tgq5", referenced from:
__T04main4testyyF in main.o
"__T0s5printySayypGd_SS9separatorSS10terminatortF", referenced from:
__T04main4testyyF in main.o
"__T0s5printySayypGd_SS9separatorSS10terminatortFfA0_", referenced from:
__T04main4testyyF in main.o
"__T0s5printySayypGd_SS9separatorSS10terminatortFfA1_", referenced from:
__T04main4testyyF in main.o
"_swift_bridgeObjectRelease", referenced from:
__T04main4testyyF in main.o
"_swift_bridgeObjectRetain", referenced from:
__T04main4testyyF in main.o
So basically I have two questions, can it be done and how?
John.
So thanx to amine.ahd's pointer, I had the iphoneos toolchain location linked instead of the mac osx's.
The following command actually compiled and let me run a c program that calls a swift native library, even with parameters (char* on the c side, UnsafePointer on the swift side).
clang -o m m.o -lshared -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L.
*-lshared is the libshared.so library that is compiled using the following command:
clang -shared -o libshared.so main.o -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
Notice the main.o, this got produced using the following command:
swiftc main.swift -emit-object
Thanx for the hints
I'm having difficulties using my built Lua.
To build my small project, I'm using:
gcc -m32 -arch i386 -I ~/Documents/lua-5.1.4/include -L ~/Documents/lua-5.1.4/lib -llua -mconsole -sectcreate __TEXT __info_plist ./Info.plist -o LuaProject -masm=intel LuaProject.cpp
I built Lua with "make macosx test". To try to make it build 32-bit, I modified the src/Makefile so that the top became:
CC= gcc
CFLAGS= -m32 -arch i386 -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS= -lm $(MYLIBS)
MYCFLAGS=
MYLDFLAGS= -m32 -arch i386
MYLIBS=
That seemed to make it for 32-bit. All I did was add -m32 -arch i386 to CFLAGS (MYCFLAGS wasn't affecting anything) and -m32 -archi386 to MYLDFLAGS. After it worked for neither -m32 nor -arch i386 individually I added both (perhaps not the best logic) which changed nothing. The build works, so then I "sudo make install local", which creates the nice folders I used to try to compile my project.
The output from gcc ends up being:
Undefined symbols for architecture i386:
"luaL_newstate()", referenced from:
_main in LuaProject-15f700.o
"luaL_openlibs(lua_State*)", referenced from:
_main in LuaProject-15f700.o
"luaL_loadbuffer(lua_State*, char const*, unsigned long, char const*)", referenced from:
_main in LuaProject-15f700.o
"lua_pcall(lua_State*, int, int, int)", referenced from:
_main in LuaProject-15f700.o
ld: symbol(s) not found for architecture i386
I am hopefully including all I need to (lua.h, lauxlib.h, lualib.h) and no errors are thrown about the -llua itself, so I am confused as to why this isn't working.
I didn't want to clutter the question with the full Lua makefile but I can upload it if needed.
I have a .f90 file which I compile with:
gfortran -c -o objs/mod_interp.o ../extern/mod_interp.f90 -g -fPIC -Imods -I../header_files -Jmods
The rest of the objects are compiled from F77 files, and then everything is linked with:
gfortran -o WIM2d.exec objs/p_WIM2d.o objs/mod_WIM2d_run.o objs/mod_interp.o objs/mod_file_utils.o objs/mod_gridinfo.o objs/mod_wim_init.o objs/mod_common_wim.o objs/mod_wim_prams.o objs/RTparam_outer.o objs/RTparam_fast.o objs/RTparam_hardcoded_v2.o objs/mod_RTparam_utilities.o objs/mod_adv_atten.o objs/mod_advect.o objs/mod_wavesice.o -g -fPIC -Imods -I../header_files
However I get the following error:
Undefined symbols for architecture x86_64:
"_r8_huge_", referenced from:
___mod_interp_MOD_pwl_interp_2d in mod_interp.o
"_r8vec_bracket5_", referenced from:
___mod_interp_MOD_pwl_interp_2d in mod_interp.o
ld: symbol(s) not found for architecture x86_64
I am working on a mac with OSX 10.10.
Any suggestions?
For linking C++ and python I used the following commands:
Compiling the actual function:
g++ -c -fpic main.cpp
Generate the wrapping C code using SWIG:
swig -c++ -python main.i
Compile the wrapping C code:
g++ -c -fpic main_wrap.cxx -I/usr/include/python2.7
for Linking everything together I used these tow instruction:
1) g++ -shared main.o main_wrap.o -o _main.so
2) g++ -lpython -shared main.o main_wrap.o -o _main.so
and got errors in both but less in the second one. (for the func.c example I checked and it only be linked with -lpython flag be set!)
however, it still gives me following errors:
Undefined symbols for architecture x86_64:
"std::vector<double, std::allocator<double> > power_method<double>(double, int)", referenced from:
__wrap_power_methodDouble in main_wrap.o
"std::vector<float, std::allocator<float> > power_method<float>(float, int)", referenced from:
__wrap_power_methodFloat in main_wrap.o
"std::vector<int, std::allocator<int> > power_method<int>(int, int)", referenced from:
__wrap_power_methodInt in main_wrap.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Show message history