I'm a n00b so correct me on anything.
I've been working on this for a couple days and have done research but can't seem to solve the issue. This is for a programming class that mainly uses Visual Studio and many of my fellow classmates didn't have a problem. Although, I'm on Xcode so maybe it has something to do with that. Basically, I'm creating a Pure Virtual objects called Geometric_Object with child classes Circle.h and Rectangle.h, however when I run the code I get the following error:
Undefined symbols for architecture x86_64:
"GeometricObject::GeometricObject()", referenced from:
Circle::Circle() in main.o
Rectangle::Rectangle() 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 beyond lost. Because I don't have enough reputation points I can't post all the links so I had to compress them as one on Dropbox. Hopefully someone can bypass this for me so nobody is afraid to unzip the contents.
https://dl.dropboxusercontent.com/u/82764116/Xcode.zip
The problem is exactly what the error says. You haven't defined GeometricObject::GeometricObject(). You also haven't defined many other methods in GeometricObject, like the destructor, getColor, setColor etc.
I'm not sure where you think the definitions for these functions are, but they aren't in the code you've linked to.
You have defined (for instance) Rectangle::Rectangle(). Just define GeometricObject::GeometricObject() in the same way (and all the other missing definitions).
Related
My code used to copmile well previously, until boost library got updated with changes in asio.
In my code, I define a variable: boost::shared_ptr<Face> face(boost::make_shared<ThreadsafeFace>(io_service)); which, as can be seen, takes io_service for the constructor. Face and ThreadsafeFace are a library classes, my app links to.
The problem occurs at linking stage of my binary, where I get undefined symbols error:
Undefined symbols for architecture x86_64:
"ndn::ThreadsafeFace::ThreadsafeFace(boost::asio::io_context&)", referenced from:
boost::detail::sp_if_not_array<ndn::ThreadsafeFace>::type boost::make_shared<ndn::ThreadsafeFace, boost::asio::io_context&>(boost::asio::io_context&&&) in ndnrtc_client-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)
As can be seen, linker can't find a constructor for ThreadsafeFace that takes boost::asio::io_context& argument. And it won't -- because library does not provide one. The only one library does provide -- is with io_service argument.
Now, I don't quite understand, where does this constructor definition come from, as neither my code, nor library's code have this definition.
This makes me think that with new boost (I'm linking against 1.67 using homebrew, macOS), io_service gets replaced by io_context automatically (during preprocessing?), thus leading to the problem.
I tried providing -DBOOST_ASIO_ENABLE_OLD_SERVICES when compiling my code, but it didn't help either.
Shall I downgrade boost version until library gets updated?
UPDATE
I've ran clang for preprocessing (clang++ -E ...) and found this in the output:
# 21 "/usr/local/include/boost/asio/io_service.hpp" 2 3
namespace boost {
namespace asio {
typedef io_context io_service;
}
}
Which confirms that all io_service variables will in fact be io_context and guarantee headaches.
"Which confirms that all io_service variables will in fact be io_context and guarantee headaches"
In fact that guarantees no headaches. Typedefs are aliases: they're exactly the same. So io_service becomes just another way to refer to the same type, even if the spelling happens to be different in some spots. This is actually what you need.
Reading the message:
Undefined symbols for architecture x86_64:
"ndn::ThreadsafeFace::ThreadsafeFace(boost::asio::io_context&)", referenced from:
boost::detail::sp_if_not_array::type boost::make_shared(boost::asio::io_context&&&) in ndnrtc_client-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)
This tells you that ndn::ThreadsafeFace does provide the required constructor, because it's referenced from your code. If it weren't provided, it would have been a compile error, not a link error.
So your problem is different. You either lack a linker input, or the library object you link against was compiled /differently/ in such a way that it doesn't provide the definition of the constructor that is declared when you include the header that declares ThreadsafeFace.
Usually, this happens if namespaces change, or when you (ab)used compiler defines to change the meaning of the code (did you perhaps mess around with something like #define io_context io_service? Because that is a recipe for headaches).
Note linker errors can even result when you use different compiler versions/flags when compiling your code versus when compiling the library.
For far more troubleshooting tips see: What is an undefined reference/unresolved external symbol error and how do I fix it?
So I am using Xcode 6.1 on my Objective-C app.
My app uses the GameKit framework.
I tried to call external C++ methods from my GameViewController (which is Objective-C source.)
To make GameViewController.mm compile, I had to set the type to 'Objective-C++ Source' manually.
However, even though the source now compiles, it will fail to link with:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_GLKViewController", referenced from:
_OBJC_CLASS_$_GameViewController in GameViewController.o
"_OBJC_METACLASS_$_GLKViewController", referenced from:
_OBJC_METACLASS_$_GameViewController in GameViewController.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 can only get rid of the linker error by setting the type back to 'Objective-C Source' and removing the calls to the external C++ functions.
Why does the linker fail if my source is compiled as 'Objective-C++ Source' instead of 'Objective-C Source' type?
Note that I properly link against GameKit in the Build-phases.
OK.
It turns out to be a weird one, but:
I was linking to GameKit, and not GLKit.
The fix: link to GLKit as well.
Now, the strange part is that not linking GLKit causes no problems if the view controller is built as Objective-C source. It does cause problems if built as Objective-C++ source.
Strange, but true.
Although XCode is not flagging any errors before compile time, it brings up 4 when I actually compile it. They are
Undefined symbols for architecture i386:
"HtmlProcessor::HtmlProcessor()", referenced from:
_main in main.o
"HtmlProcessor::~HtmlProcessor()", referenced from:
_main in main.o
"DocTree::_hp", referenced from:
DocTree::setTree(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in HtmlProcessor.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have searched the web high and low for answers. Most of them mention changing the Architectures settings. Right now I have
Architectures: Universal (32/64-bit Intel) (x86_64, i386)
Base SDK: Latest OFX (OS X 10.9)
Build Active Architecture Only: No
Supported Platforms: OSX
Valid Architectures: i386
and I've fiddled around with everything to try and get my damn program to compile. I don't even care what the target architecture is ..... I'm making this program for my own amusement and want it to run on my machine, a MacBook Pro running OS X 10.9.4. I just want this damn console program to work. You would think that XCode would have default configurations for your program to run on your machine.
Here are the source files: https://www.dropbox.com/sh/yu7tblwj14eoq1l/AAC8PfDi6la3CjE167Iz1C0da?dl=0
Nobel Prize to the Stack Overflow guru who bails me out of this one.
You declared a static class member, but you did not define it in any module:
class DocTree {
//...
static HtmlProcessor _hp;
//...
};
This needs to have this in one and only one module:
HtmlProcessor DocTree::_hp;
You are declaring the functions in the header file but do not define (implement) them in the .cpp file. I couldn't find the definition for the constructor and destructor in the .cpp file, although you have the declaration in the header. The linker then complains as it is not able to find the needed object code to create the instance of HtmlProcessor.
So make sure that you either declare the ctor as empty, like
HtmlProcessor(){}
or remove the declaration altogether,
or use =default (if you use C++11).
Same for the static declaration of DocTree::_hp;, you need to define it somewhere.
I have taken this example directly from a book on C++ (shortened it so it's easier to see what the problem is).
My class won't compile with g++. The class is:
class stack{
private:
int count;
public:
void init(void);
};
inline void stack::init(void){
count= 0;
}
~
As you can see, I'm trying to prototype my functions inside the class, then define them outside the class. The book did exactly what I am trying this, but it doesn't work. Where is the mistake? Is it my computer (I'm using a mac). The error I get is the question, but also here:
user-MacBook-Pro:cplusplus trevortruog$ g++ Stack2.cpp
Undefined symbols for architecture x86_64: "_main", referenced from:
start in crt1.10.6.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status
The code compiles fine. It just doesn’t do anything useful since it’s missing a main function and therefore no executable can be generated from it.
This is not an error in the compiler but rather in the linker, which precisely complains about the lack of an entry point. You can see this from the error message:
ld: symbol(s) not found for architecture
The first thing, ld, is the name of the application which created the error message. ld is the linker application which is (internally) called by the actual compiler. Once that gets called, the code is already compiled.
Add a main function to solve the linker error.
As an added comment, the code uses bad practice. This is a sure hint that the programming book you’re using is bad. Unfortunately, bad teaching material is the bane of C++, which is a highly complex language even when taught correctly. Do yourself a favour and ditch the book in favour of a good one.
I recently upgraded to Xcode 5.0 and I am having problems with my command line C++ projects. Judging from answers on various forums, the problem lies with either my framework, or Xcode 5.0 not clearing out my "Library Search Paths" build setting.
When I do try clear out my library search path I find that it is empty. I have pasted my error below.
Undefined symbols for architecture x86_64:
"queueExam<int>::queueExam(int)", referenced from:
_main in examMain.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
There can be two possibilities.
1. Either your constructor name queueExam::queueExam(int) has an error, i mean some spelling error.(As it says that the symbol is not defined)
2. Your program has compiled, but there is a problem while combining the .cpp files which you have created. (Linker Error)
So i suggest that you check on this.
If none of this work, try creating a new project and just copy paste the whole code into the new one.(This solves linker problems many times).