Ok, I just switched to MacOS after a while of Windows/Linux coexistence. I open a simple text editor, write a simple program just to check if everything is all right. I know there are other threads about this error but it just seems that in all the other cases the problem lied in a specific part of their program, which in turn is far more complex than this. I just want to understand why the compiler says what it says even with a simple thing like this.
#include <iostream>
#include "numeri.h"
int main(void)
{
std::cout << numeri() << std::endl;
return 0;
}
with
//numeri.h
int numeri(void);
and
//numeri.cpp
#include "numeri.h"
int numeri(void)
{
return (3);
}
what I get from gcc helloworld.cpp -Wall is
Undefined symbols for architecture x86_64:
"numeri()", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in cc6WY2MJ.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cc6WY2MJ.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in cc6WY2MJ.o
"std::cout", referenced from:
_main in cc6WY2MJ.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in cc6WY2MJ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
2 cases:
1 - I forgot how to use a simple header (I prefix, I'm a physics student, I can program for what it regards physics and numeric simulations [or at least, I could], but I just don't know that much about linkers-compilers-architecture and this kind of stuff)
2 - something's wrong
The C++ compiler is g++, . Also you need to add numeri.cpp to your commmand line.
g++ helloworld.cpp numeri.cpp -Wall
Related
I followed the instruction on thier github https://github.com/openvinotoolkit/openvino to build it on macOS, done it and when i wrote a small code to check was all clear or not
#include <string>
#include <iostream>
#include <dlfcn.h>
#include <fstream>
#define USE_STATIC_IE
#define _CRT_SECURE_NO_WARNINGS
#include <ie_core.hpp>
using namespace :: std;
int main(){
dlopen("/Users/nk/Documents/HZ/openvino/inference-engine/temp/tbb/lib/libtbb.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libngraph.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_transformations.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_legacy.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libinference_engine_lp_transformations.dylib", RTLD_LAZY);
dlopen("/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/libMKLDNNPlugin.dylib", RTLD_LAZY);
const std::string pluginsFilePath = "/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib/plugins.xml";
InferenceEngine::Core ie(pluginsFilePath);
const auto info = ie.GetVersions("CPU");
if(!info.empty())
cout << "Yes";
return 0;
}
when i compile it with command
g++ -std=c++11 -I/Users/nk/Documents/HZ/openvino/inference-engine/include testdll.cpp -o testdll && "/Users/nk/Documents/FelenaSoft/"testdll
it gave me the error
Undefined symbols for architecture x86_64:
"InferenceEngine::Core::Core(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in testdll-788073.o
"InferenceEngine::Core::GetVersions(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:
_main in testdll-788073.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
then i added .a libs and ran this command
g++ -std=c++11 -L/Users/nk/Documents/HZ/openvino/bin/intel64/Release/lib -lmkldnn -lpugixml -linference_engine_s -I/Users/nk/Documents/HZ/openvino/inference-engine/include testdll.cpp -o testdll && "/Users/nk/Documents/FelenaSoft/"testdll
and i got this
Undefined symbols for architecture x86_64:
"ngraph::as_output_vector(std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&)", referenced from:
ngraph::Node::generate_adjoints(ngraph::autodiff::Adjoints&, std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&) in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::match_node(ngraph::pattern::Matcher*, ngraph::Output<ngraph::Node> const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::match_value(ngraph::pattern::Matcher*, ngraph::Output<ngraph::Node> const&, ngraph::Output<ngraph::Node> const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::constant_fold(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > >&, std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::set_arguments(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&)", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::set_output_type(unsigned long, ngraph::element::Type const&, ngraph::PartialShape const&)", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::m_next_instance_id", referenced from:
std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode> std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode>::make_shared<>() in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::validate_and_infer_types()", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::evaluate(std::__1::vector<std::__1::shared_ptr<ngraph::runtime::HostTensor>, std::__1::allocator<std::__1::shared_ptr<ngraph::runtime::HostTensor> > > const&, std::__1::vector<std::__1::shared_ptr<ngraph::runtime::HostTensor>, std::__1::allocator<std::__1::shared_ptr<ngraph::runtime::HostTensor> > > const&)", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::~Node()", referenced from:
ExecGraphInfoSerialization::ExecutionNode::~ExecutionNode() in libinference_engine_s.a(ie_rtti.cpp.o)
ExecGraphInfoSerialization::ExecutionNode::~ExecutionNode() in libinference_engine_s.a(ie_rtti.cpp.o)
std::__1::__shared_ptr_emplace<ExecGraphInfoSerialization::ExecutionNode, std::__1::allocator<ExecGraphInfoSerialization::ExecutionNode> >::~__shared_ptr_emplace() in libinference_engine_s.a(ie_rtti.cpp.o)
std::__1::__shared_ptr_emplace<ExecGraphInfoSerialization::ExecutionNode, std::__1::allocator<ExecGraphInfoSerialization::ExecutionNode> >::~__shared_ptr_emplace() in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_dynamic() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::description() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_constant() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_arguments() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_size() const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::write_description(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int) const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::copy_with_new_args(std::__1::vector<std::__1::shared_ptr<ngraph::Node>, std::__1::allocator<std::__1::shared_ptr<ngraph::Node> > > const&) const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_element_type(unsigned long) const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_default_output_index() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_output_partial_shape(unsigned long) const", referenced from:
ExecGraphInfoSerialization::ExecutionNode::clone_with_new_inputs(std::__1::vector<ngraph::Output<ngraph::Node>, std::__1::allocator<ngraph::Output<ngraph::Node> > > const&) const in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::get_autob() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"ngraph::Node::is_output() const", referenced from:
vtable for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"typeinfo for ngraph::Node", referenced from:
typeinfo for ExecGraphInfoSerialization::ExecutionNode in libinference_engine_s.a(ie_rtti.cpp.o)
"vtable for ngraph::Node", referenced from:
std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode> std::__1::shared_ptr<ExecGraphInfoSerialization::ExecutionNode>::make_shared<>() in libinference_engine_s.a(ie_rtti.cpp.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did anyone had the same problem as me, and did anyone know how to fix it?
First and foremost just need to cross check with you on your toolkit installation. Since you are trying to run a model already, I assume you already set it up properly as in (fyi latest version is 2020.4): https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
The error that you are getting, the Undefined symbols for architecture x86_64 is an Xcode build failure indicating you missed out something in your inference engine or the way you link the model with certain resources are incorrect or some other reasons. As long as this error persist you won't be able to compile your code. That is why you got the linker command failed with exit code 1.
Most error occurs because the users did not Set the OpenVINO environment variables or Configure the Model Optimizer correctly. This is why it's really important to Run verification scripts to verify installation and compile samples.
Before running any custom model, it is good to have a solid working Openvino environment, hence please help to check whether you could run the default models as in example here https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
By default, you should already have pre-trained models including open zoo model, Model Optimizer and Inference Engine which are working example to work with if you configured the toolkit correctly. These should already located in your installed toolkit's directory which you don't have to install separately from other resources.
Please take a note that you need:
CMake 3.4 or higher,
Python 3.5 or higher,
Apple Xcode Command Line Tools*,
(Optional) Apple Xcode* IDE (not required for OpenVINO, but useful for development),
And supported MAC OS is macOS 10.14.4*
Again, please help to cross check what you have in your Openvino environment and steps you had used to configure with the official documentation https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_macos.html
Thanks!
I'm trying to use Openmp on my mac, but i'm getting a compiler error I don't understand. I installed openmp using
brew install llvm
When I try to compile my code using -fopenmp I get errors like this
Undefined symbols for architecture x86_64:
"std::runtime_error::what() const", referenced from:
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::runtime_error> > in ccOEbbPM.o
vtable for boost::exception_detail::error_info_injector<std::runtime_error> in ccOEbbPM.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::range_error> > in ccOEbbPM.o
vtable for boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::overflow_error> > in ccOEbbPM.o
vtable for boost::exception_detail::error_info_injector<std::range_error> in ccOEbbPM.o
vtable for boost::exception_detail::error_info_injector<std::overflow_error> in ccOEbbPM.o
"std::locale::operator==(std::locale const&) const", referenced from:
boost::detail::lcast_put_unsigned<std::char_traits<char>, unsigned long long, char>::convert() in ccOEbbPM.o
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_not_of(char, unsigned long) const", referenced from:
boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >::do_get_string[abi:cxx11](std::_Ios_Fmtflags, mpl_::bool_<false> const&) const in ccOEbbPM.o
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
std::basic_ostream<char, std::char_traits<char> >& boost::multiprecision::operator<< <boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >, (boost::multiprecision::expression_template_option)1>(std::basic_ostream<char, std::char_traits<char> >&, boost::multiprecision::number<boost::multiprecision::backends::cpp_int_backend<0u, 0u, (boost::multiprecision::cpp_integer_type)1, (boost::multiprecision::cpp_int_check_type)0, std::allocator<unsigned long long> >, (boost::multiprecision::expression_template_option)1> const&) in ccOEbbPM.o
It's just a small segment of the error code since it goes on for quite a while, but I post the rest if need be. I also have the boost library installed.
Any help is appreciated, thanks.
EDIT:
Simple program that causes the error:
#include <iostream>
#include <omp.h>
using namespace std;
int main(){
int x = 5;
#pragma omp parallel
for(int y = 0; y < 50;y++){
x += 5;
}
cout << x << endl;
return 0;
}
Commands used to compile:
gcc-7 -fopenmp -Wall ex.cc
gcc-7 -std=c++11 -fopenmp -Wall ex.cc (I get less errors doing it this way)
Error when using the second compile command:
Undefined symbols for architecture x86_64:
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)
(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in ccXt8Pa8.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in ccXt8Pa8.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccXt8Pa8.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccXt8Pa8.o
"std::cout", referenced from:
_main in ccXt8Pa8.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in ccXt8Pa8.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Use g++-7 rather than gcc-7, and all will be fine - it is C++ after all ;-)
g++-7 -std=c++11 -fopenmp openmp.cpp -o openmp
I write code like this in my Mac OS X v10.8 (Mountain Lion), and when I use "gcc use_new.cpp -o use_new" to compile it, it throws a wrong message like this:
Undefined symbols for architecture x86_64:
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in ccr2vrRQ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(void const*)", referenced from:
_main in ccr2vrRQ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(double)", referenced from:
_main in ccr2vrRQ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in ccr2vrRQ.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(unsigned long)", referenced from:
_main in ccr2vrRQ.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccr2vrRQ.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccr2vrRQ.o
"std::cout", referenced from:
_main in ccr2vrRQ.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in ccr2vrRQ.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccr2vrRQ.o
"operator delete(void*)", referenced from:
_main in ccr2vrRQ.o
"operator new(unsigned long)", referenced from:
_main in ccr2vrRQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
And when I use "g++ use_new.cpp -o use_new" it is OK. How can I fix this?
#include <iostream>
struct fish
{
float weight;
int id;
int kind;
};
int main()
{
using namespace std;
int* pt = new int;
*pt = 1001;
cout << "int: " << *pt << "in location: " << pt << endl;
double* pd = new double;
*pd = 100000001.0;
cout << "double: " << *pd << "in location: " << pd << endl;
cout << "int point pt is length " << sizeof(*pt) << endl;
cout << "double point pd is length " << sizeof(*pd) << endl;
delete pt;
delete pd;
cout << (int *)"How are you!" << endl;
return 0;
}
This is the case even with the old 4.2 GCC (I experienced this when I set up my unofficial iOS toolchain). gcc assumes C by default, and invokes the linker without linking to the C++ standard library; in contrast, g++ assumes C++ and links against the C++ standard library by default.
All in all - possible solutions:
gcc myprog.c -o myprog -lstdc++
or
g++ myprog.c -o myprog
The answer to this Stack Overflow question has the answer
gcc and g++ linker
Use
gcc -lstdc++ use_new.cpp -o use_new
The -lstdc++ flag tells the linker to include the C++ Standard Library.
I'm running Mac OS X v10.7.4 (Lion) and the library is located here:
/usr/lib/libstdc++.dylib
This isn't related to the code pasted by #user1582840, just my two cents, and from a different cause of the same problem in g++ when working on some of my own code:
I received the "ld: symbol(s) not found for architecture x86_64" error when using g++ 4.2.1 on OS X v10.8 (Mountain Lion)/Darwin 11 for a different reason.
I received this error because I had a Class defined. In the class definition, I declared member functions. However, when I defined the member functions I forgot to include the class modifier.
So for an example of what I'm talking about (code sample, not full program):
class NewClass
{
NewClass(); // Default constructor
};
Then later, when defining the NewClass() constructor (or any member function) I simply had:
// Don't do this. It will throw that error!!
NewClass()
{
// Do whatever
}
rather than:
// Proper way
NewClass::NewClass()
{
// Do whatever
}
This is a rather simple mistake, and I managed to catch it in a short amount of time luckily, but it could be easy for someone to miss (us newbies especially), and the solutions about gcc/g++ linkers, Xcode, etc. aren't any help for this :P
I started learning C++ and I tried to run the classic Hello World program:
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello, World!";
return 0;
}
but when I compile it in terminal using GCC I always get that error:
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const", referenced from:
std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccpe3DPY.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const", referenced from:
std::__verify_grouping(char const*, unsigned long, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)in ccpe3DPY.o
"std::cout", referenced from:
_main in ccpe3DPY.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccpe3DPY.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccpe3DPY.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccpe3DPY.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in ccpe3DPY.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
can you tell me why?
You've compiled your program with gcc, which is a C compiler, not a C++ compiler. Use g++ instead; it knows to include the C++ run-time libraries, where those missing symbols are defined.
Thats a C compiler you need to use a C++ compiler like rob says above g++. Also if you are a beginner I would highly recommend using Microsoft visual studio express if you run a windows OS; if not then netbeans.
I wrote a program to create gnuplot commands according to data that was read from an input file. I required far too many commands to do this by hand. This worked quite nicely, but I now need to read data from two different data files and use these to create the gnuplot commands. Unfortunately something now seems to be going wrong with the reading of the two files. The portion of code involved in reading from the data files is as follows:
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int n_snapshots;
int main () {
std::cout << "Enter number of snapshots" << "\n";
std::cin >> n_snapshots;
int snap_cell_count[n_snapshots];
std::ifstream in_file_count("data/snapshot_data");
std::ifstream in_file_fates("data/cell_fates_data_final");
for (int i=0; i<n_snapshots; i++) {
in_file_count >> snap_cell_count[i];
}
in_file_count.close();
int cell_fates[snap_cell_count[n_snapshots-1]];
for (int i=0; i<snap_cell_count[n_snapshots-1]; i++) {
in_file_fates >> cell_fates[i];
}
in_file_fates.close();
n_snapshots is simply some integer, snap_cell_count[] is an array with "n_shapshots" elements, each of which takes a value read from the data file "snapshot_data". cell_fates[] is an array with a number of elements that is equal to the value of the last element in snap_cell_count[], and again the values of its elements are read from a file, in this case "cell_fates_data_final". The data files to be read from are stored in a folder called "data".
Unfortunately, the compiler returns the following errors.
Undefined symbols for architecture x86_64:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const", referenced from:
_main in ccrpSAv5.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::str() const", referenced from:
_main in ccrpSAv5.o
"std::basic_istream<char, std::char_traits<char> >::operator>>(int&)", referenced from:
_main in ccrpSAv5.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in ccrpSAv5.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
_main in ccrpSAv5.o
"std::basic_ifstream<char, std::char_traits<char> >::close()", referenced from:
_main in ccrpSAv5.o
"std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_Ios_Openmode)", referenced from:
_main in ccrpSAv5.o
"std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()", referenced from:
_main in ccrpSAv5.o
"std::basic_ofstream<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode)", referenced from:
_main in ccrpSAv5.o
"std::basic_ofstream<char, std::char_traits<char> >::close()", referenced from:
_main in ccrpSAv5.o
"std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream()", referenced from:
_main in ccrpSAv5.o
"std::basic_ofstream<char, std::char_traits<char> >::~basic_ofstream()", referenced from:
_main in ccrpSAv5.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)", referenced from:
_main in ccrpSAv5.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()", referenced from:
_main in ccrpSAv5.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccrpSAv5.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccrpSAv5.o
"std::cin", referenced from:
_main in ccrpSAv5.o
"std::cout", referenced from:
_main in ccrpSAv5.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccrpSAv5.o
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in ccrpSAv5.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
This is being compiled with the gcc compiler on Mac OSX Mountain Lion.
Does anyone have any idea what's wrong here?
Well, for starters you can't just say int snap_cell_count[n_snapshots] with the value of n_snapshots being determined at runtime. You have to do something like
int *snap_cell_count = new int[n_snapshots];
// do some stuff
delete[] snap_cell_count;
Same thing for cell_fates
As for your linker errors, maybe this question solves your issues...