How to fix ncurses? [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I'm a mac user, and I'm using the XCode developer tools and using CLion as a compiler. When I try to use ncurses and its functions, specifically getch(), I get the following error.
Undefined symbols for architecture x86_64:
"_stdscr", referenced from:
_main in main.cpp.o
"_wgetch", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
I've tried to go online and reinstall ncurses, but it hasn't fixed anything. I would greatly appreciate any help.

First of all, CLion isn't a compiler. It's an IDEA (integrated development
environment). As I remember using it last time it uses CMake as a build tool. And CMake uses GCC, Clang, MSVC, whatever under the hood.
As you don't post any code sample I will try to guess the problem. Usually
when using ncurses you need to link with it as: -lncurses. For more info you
should look man ncurses on your platform. Also check that you don't forget to include the required header. E.g. on my system it's #include <curses.h>.
How to link with ncurses via CMake

Related

Yet another "ld: symbol(s) not found for architecture x86_64" issue with boost, this time with mgiza

I apologize for asking such a common question; I can't find any solution out there that works or is clear enough for me to implement. I am simply trying to install mgiza. Here is the INSTALL file:
cmake .
make
make install
If you want to install to a custom location, add the following flag when you run cmake:
-DCMAKE_INSTALL_PREFIX=/path/to/custom/location
NOTE: Boost Version 1.48 has problem with the code, you can use either 1.46 or 1.50+. Unfortunately 1.48 is shipped with Ubuntu 12.04 LTS, you can either download and compile libboost 1.50+ from their website, or just do this:
sudo apt-get install libboost1.46-all-dev
Looks easy, right? Typing in cmake . works without any apparent problems. Unfortunately, make runs into this dreaded error ("undefined symbols ...") with boost.
1 warning generated.
Linking CXX executable ../bin/d4norm
Undefined symbols for architecture x86_64:
"std::string::_Rep::_M_destroy(std::allocator<char> const&)", referenced from:
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
"std::string::_Rep::_S_empty_rep_storage", referenced from:
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
"std::string::assign(char const*, unsigned long)", referenced from:
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)", referenced from:
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system-mt.a(error_code.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Based on other questions, it's a problem with Mavericks because it uses clang to compile c++ code, implying that the library is libc++, not libstdc++. For completeness, and so that others can reproduce my errors, I am using OS X 10.9.5, Xcode 6.1, and my boost version is 1.56 (boost was installed via homebrew).
Now, there has to be some fix out there, right? Let's go through some of them:
Applying the -m32 flag: not applicable because the Makefile
doesn't have any "g++" in it, and it also explicitly tells me NOT to
edit it, because it's a "Cmake" generated file.
Not defining something in a header file: not applicable because the code should be ready to compile.
Adding -stdlib=libstdc++ to linker: I am not sure how to add this to a make command? I tried just doing make -stdlib=libstdc++ and while that seemed to avoid the errors above, it introduced some additional errors: make: *** [all] Error 2 (not sure what that means).
Linking to proper boost libraries: There's a comment there that says "You just need to link to the proper boost libraries ... plenty of Q/As on how to do that". Unfortunately, I don't think any of the questions that commenter linked to address my problem.
Linking Qt with boost: I don't think this is applicable because I'm not using Qt, and I don't know where I'd put in a LIBS += [...] boost line.
Linking a missing file: That issue seems to be more about linking when running g++ but I'm using a Makefile that doesn't have g++ anywhere in it.
Using g++ vs gcc: I don't know how I can change which of these I use, because I'm using cmake and make...
Changing a link command: Again, I don't know how I can change the compilation from cmake/make to gcc. (Note: from this point on, I will ignore most questions that are answered by adding something to gcc or g++.)
Changing the standard c++ library: the solution involves going into Xcode and changing the libraries there. I don't think this is the correct approach and in any case I'd probably screw up something if I changed a setting in Xcode (I also have no experience with Xcode's GUI).
Linking libraries in Xcode: I think this is a similar case as #9 on this list. The answer here also recommends using homebrew instead of macports for installing boost, but I already said earlier that I used homebrew for installing boost.
Compile with clang: A similar issue, but how do I get cmake or make to compile with clang?
From a (popular) bitcoin issue: Now this looks interesting! A ton of people ran into my error. Unfortunately, there seems to be no consensus or easy solution. There are also a few solutions that I don't know to implement. For instance, one solution by "imbolo" there is to compile boost using a cxxflag flag, but what does that mean?
So I'm at a little bit of a loss on how to correctly install mgiza ... I mean, the whole point of mgiza giving me cmake and make is so that I don't have to worry about the messy details of compiling things, right? This isn't just an mgiza issue, though, since I've run into this problem when trying to do make elsewhere. I understand the high-level ideas of (C)Makefiles, but not the low-level details.
To address some of the concerns by the commenters: the best way to deal with this problem is to try and clear your system as much as possible and start the process from scratch.
Also, since this was posted, OS X 10.10 Yosemite was released, which may have fixed this problem (IIRC this problem is mostly due to 10.9 and the clang/gcc complier changes).

C++ Dynamically Linked Libraries loaded at runtime - Poco / qmake

I am having trouble with Boost and my Mac OS X.
I am using Qt Creator as a development platform for C++ projects, primarily because of the IDE and qmake.
Right now I am working on a C++ app that is supposed to be cross-platform but I do not want to use the Qt framework itself. Instead I am using the STD libraries (C++11), Poco and Boost.
One of the things I am trying to achieve is a plugin system that loads dynamically linked libraries at runtime.
I saw a few projects like Boost-extension which is no longer supported and several others.
Right now I am using Poco's Shared Libraries and their Class Loader. I am following closely the tutorial at the end of the presentation. Unfortunately I cannot get it working and I am receiving the following error upon compilation, where the ServiceBase class is my plugin interface.
Undefined symbols for architecture x86_64:
"Poco::SharedLibrary::getSymbol(std::string const&)", referenced from:
Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
"Poco::SharedLibrary::hasSymbol(std::string const&)", referenced from:
Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
"Poco::SharedLibrary::SharedLibrary(std::string const&)", referenced from:
Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
"Poco::SystemException::SystemException(std::string const&, int)", referenced from:
Poco::MutexImpl::unlockImpl() in main.o
Poco::MutexImpl::lockImpl() in main.o
"Poco::LibraryLoadException::LibraryLoadException(std::string const&, std::string const&, int)", referenced from:
Poco::ClassLoader<ServiceBase>::loadLibrary(std::string const&, std::string const&) in main.o
ld: symbol(s) not found for architecture x86_64
I have the Poco libraries linked and pretty much everything seems to be implemented.
Any advice on how to fix that?
P.S. I am also looking for alternatives on implementing the plugin system, probably more-powerful and certainly cross-platform.
Disclaimer. I have no experience with this Poco library.
Without further details on your environment or your tools... I can only provide some very general advice:
How I'd chase this is:
Locate in what library or object file are defined the symbols reported as undefined symbols. On unix-like environments this can be achieved with the nm tool
Verify that the libraries or objects are compiled on the right architecture (I see you're using x86_64) file tool might help you there
Verify that you're referring to the library in the linker command line (look for a -l for dynamic or static libraries) or that you're including the object file or the static library in the list of things to link.
Verify that you're referring to the right library (either through -L flags or the LD_LIBRARY_PATH env variable (or LD_LIBRARY_PATH_64 in some systems e.g. Solaris for 64bits build)
I know you said you have linked the Poco libraries, but the error is clearly that a symbol is missing. Either the library is missing or you need to fiddle with the order of the -l flags to satisfy the dependencies. The nm might help you there in determining what objects or libraries refer to the symbol (must come first) and what objects or libraries define the symbol (must come later).
Sorry not being of more help.
P.S. In addition you might want to look at Linking error with Poco Net which might be related.
One more reference to a question that details different causes for linker errors: What is an undefined reference/unresolved external symbol error and how do I fix it?

Why can't I compile SDL on Mac for x86_64 using C++?

I'm running on a Mac Mini, late 2012 (The latest), 64 bit, Intel Core i7 2.3 gHz HyperThreading x86_64, or so says my computer. I'm also using Code::blocks for the time being because help in Xcode (which I would prefer) is even more sparse because I am using C++. That said, programming language of choice is C++, and will eventually expand into Objective-C++, but that's for another day.
The problem is this: I am trying to compile a program that will do I'm not quite sure what yet (it's a template, let's just say it's a game for now.) using SDL 1.2.15, which I have compiled from source on my Mac. (I did try using SDLmain.m and SDL.h, but that was full of Objective-C code, and as I could find no good information on whether I could code in C++ with these on the internet, I gave up.) The source I compiled seems to work just fine, Code::Blocks can compile it's tutorial just fine and it runs ok. However, I cannot seem to get my game template to work. It compiles fine, with no errors or warnings, but the linker does not do the same. Now, I'm really not sure what ld does, I just know that it links together code. (Anyone want to elaborate on that?) When Code::Blocks gets to it's linking step it fails with this message:
-------------- Clean: Debug in PyroLauncher ---------------
Cleaned "PyroLauncher - Debug"
-------------- Build: Debug in PyroLauncher ---------------
Compiling: App.cpp
Compiling: OnCleanup.cpp
Compiling: OnEvent.cpp
Compiling: OnInit.cpp
Compiling: OnLoop.cpp
Compiling: OnRender.cpp
Linking console executable: bin/Debug/PyroLauncher
Undefined symbols for architecture x86_64:
"_SDL_GetError", referenced from:
App::OnInit() in OnInit.o
"_SDL_Init", referenced from:
App::OnInit() in OnInit.o
"_SDL_PollEvent", referenced from:
App::OnExecute() in App.o
"_SDL_Quit", referenced from:
App::OnCleanup() in OnCleanup.o
"_SDL_SetVideoMode", referenced from:
App::OnInit() in OnInit.o
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
Which has me seriously confused. I just know that ld can't find for my native architecture x86_64. If anyone can help me, it would be greatly appreciated.
What I think the solutions may be: (I don't know how to do them, however.)
SDL is not compiled for 64 bit, and therefore cannot be compiled against with 64 bit code.
SDL is compiled for Objective-C, and therefore cannot be used with code in C++.
My code is 32 bit, SDL is 64 bit, and they are not compatible.
Do you understand what is happening here? Your code is calling functions which the linker (ld) can't find.
The two main probabilities are that you either need to include some more files in your project, or that you need to define some macros.
Search through the project for the definition of SDL_GetError() (and the others). If you don't find it, then you need to find the file which declares it and include that.
If you do find it, then it will probably be surrounded by #ifdef XXXX and you will have to define xxxx in your project options (not in your code). Most good IDEs (I use NetBeans, with Cygwin for C+ development) will grey out the then contents of an ifdef if it isn't defined, so you can imemdiately see if that is the case.
Btw, have a look around the SDL website for installation instructions. Alternatively, your download might have a file called "Install" or "Install.txt", and may also have a Makefile. If it does, then in your IDE look for an option Project/New ... from existing makefile.
Hope this helps.
You need to add the files SDLMain.m and SDLMain.h to your project. The SDLMain files contain glue code so SDL code can run on Mac OS X. You also need to link the Cocoa framework to your project. The Mac version of SDL is written in Cocoa so you need to link to Cocoa. Linking the Cocoa framework does not force you to use Objective-C. You can write your game in C++.
If you're looking for information on setting up SDL with Xcode 4, read the following article:
Using SDL with Xcode 4

link error __stack_chk_fail (using libs with xcode)

I'm trying to compile a C++ app in xcode using gcc 4.0 and and the 10.4u SDK.
I get the following linker error.
"_stack_chk_fail", referenced from:
_read_frame_ in libAudioDecoder.a(stream_decoder.o)
_read_metadata_ in libAudioDecoder.a(stream_decoder.o)
"_stack_chk_guard", referenced from:
___stack_chk_guard$non_lazy_ptr in libAudioDecoder.a(stream_decoder.o)
(maybe you meant: ___stack_chk_guard$non_lazy_ptr)
ld: symbol(s) not found
Other help threads suggest that all I need to do is add...
-fno-stack-protector
...to the 'Other C Flags', which is what I've done, but the problem persists. I've done cleans, rebuilds and even restarted XCode (because it's been known to get confused sometimes), but the problem persists.
Note that libAudioDecoder is my own library that I'm trying to link with. stream_decoder.o is apart of the FLAC library which libAudioDecoder links to.
Essentially my project links with libAudioDecoder which links with libFlac, where libFlac has also been compile using an xcode project.
For each three xcode projects, I'm using gcc 4.0 and and the 10.4u SDK and have 'Other C Flags' and 'Other C++ Flags' set with -fno-stack-protector.
I'm all out of ideas at the moment, so would appreciate some help with this.
Cheers.
Symbol _stack_chk_fail is referenced from symbol _read_frame_ in your libAudioDecoder.a library, not the Xcode project from which you are linking against libAudioDecoder.a. Try to go back and rebuild libAudioDecoder.a with the -fno-stack-protector flag?
It sounds like you may have compiled the library linking against a newer version of libc and are now compiling with an older version, or some other mismatch like that. Searching for "_stack_chk_fail" on StackOverflow will lead you to a ton of other tips.

additional c++ sources generating errors in Xcode

I have some source written by one of my colleagues in C++. They are stuffs for numerical analysis. I wish them to be included in my Objective-C/Cocoa project. Building seems not to be accomplished... with a kinda error message:
Undefined symbols for architecture x86_64:
"_calcThomas", 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)
I'm a novice in Xcode or clang. I have a lot of Xcode documentation, and can't find a related one to solve my own. How to achieve my project to work with c++?
Additionally,
The original c++ sources are pure c++ code composed of c++ sources and headers.
They are compiled perfectly in case the project is created only with c++ code template, not with Foundation template.
Thanks hopefully.