error LNK2001: unresolved external symbol

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 5557 Views - Last Post: 13 November 2011 - 03:16 PM Rate Topic: -----

#1 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

error LNK2001: unresolved external symbol

Posted 12 November 2011 - 10:52 AM

Hi
I've managed to port and compile a Linux App onto Win32 Vista(VC++ 2008). Although it .obj files are generated it gives these linker errors which are giving me a hard time.
Full error description:

traffic.obj : error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct Position const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABUPosition@@@Z)


I have searched for a solution but only found cases in which one needed to link a project with a specific .lib file; I need not to do that for I don't have any library files.

Any help/suggestion/code/reference will be very much appreciated.

Sebi

Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2001: unresolved external symbol

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 10:58 AM

Yes it could be that you need to link a library or probably more likely that you are passing the wrong type of parameter to a function and it can't find a matching function signature.

For instance... if you have a function called "add" and takes two integers, but then you try to pass it 1 integer or an integer and a string it will throw this kind of error basically saying "I don't see a function called add that takes an integer and a string".

So look in your traffic.cpp for a place where you could possibly be sending a bad value to something like cout.

The debug window should also be giving you a line number. Double click the error message and it will probably take you right to the bad line. Try showing us the function that the error is appearing in too and we can help further.

Thanks! :)
Was This Post Helpful? 0
  • +
  • -

#3 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 11:09 AM

View PostMartyr2, on 12 November 2011 - 10:58 AM, said:

Yes it could be that you need to link a library or probably more likely that you are passing the wrong type of parameter to a function and it can't find a matching function signature.

For instance... if you have a function called "add" and takes two integers, but then you try to pass it 1 integer or an integer and a string it will throw this kind of error basically saying "I don't see a function called add that takes an integer and a string".

So look in your traffic.cpp for a place where you could possibly be sending a bad value to something like cout.

The debug window should also be giving you a line number. Double click the error message and it will probably take you right to the bad line. Try showing us the function that the error is appearing in too and we can help further.

Thanks! :)


Thank you for your quick reply. VS2008 only points to source file errors. These are the erronous lines:

In traffic.cpp:

bool Traffic_sink::consume_a_packet(void) {
	pPacket packet = get_packet();

	if (packet) {
		packet->set_death_time(net_clock.get_clock());

		if (param.verbose)
			cout << "[I] Consumed a packet with id " << packet->get_id() 
			<< " from " << packet->get_src_position() << " to " << packet->get_dst_position() 
			<< " at sink " << id << " latency = " << packet->get_latency() 
			<< " network_latency = " << packet->get_network_latency() 
			<< " (time = " << net_clock.get_clock() << ")\n";

		// Performance data collection
		param.n_of_packets = param.n_of_packets-1; //UYO
		if (param.print_n_of_packets) {
			param.packets_t << net_clock.get_clock() <<"\t" << param.n_of_packets << endl;
		}

		if (net_clock.get_clock() > param.warmup_period) {
			int latency = packet->get_latency();
			assert(latency > 0);

			param.n_of_received_packets ++;
			param.total_latency += latency;

			param.n_t = ((param.n_t*param.n_cnt)+param.n_of_packets)/(param.n_cnt+1); // UYO
			param.n_cnt = param.n_cnt+1;  //UYO
			//	    printf("%f  %f  %f \n",param.n_cnt,param.n_of_packets,param.n_t);
		}

		param.on_off_complete_time =  net_clock.get_clock();

		delete packet;
		return true;
	}
	else
		return false;
}



Could it be that cout does not implicitly convert it's parameters to string?

in arbiter.cpp:
 bool Arbiter::process_requests_of_port(unsigned int dir) {
  ....

  if (param.extreme_verbose) 
		cout << "[I] arbiter at router " 
		<< router->get_position() << " granted a connection from " 
		<< a_channel->get_position() << " at router " << router->get_position() 
		<< " (time = " << net_clock.get_clock() << ")\n";

}

 void Arbiter::receive_connection_request(pSw_connection_request req) {
	// process request here
	request_queue[req->dir].push_back(req);
	orion_record_arbiter_power(req->dir);

	// ebit model only need to record once
	if (net_clock.get_clock() > param.warmup_period) 
		param.energy.arbiter_energy += param.arbiter_epacket; 

	if (param.extreme_verbose) 
		cout << "[I] arbiter at router " 
		<< router->get_position() << " receive a connection request " 
		<< " (time = " << net_clock.get_clock() << ")\n";
}



Similar situation as above.

In channel.cpp
bool Output_channel::send(void) {
#ifdef DEBUG
	assert(can_send());
#endif

	pFlit a_flit = get_flit();  // send a flit

	if (param.extreme_verbose && a_flit->is_header()) {
		if (this->router) {
			cout << "[I] Output channel " << pos << " at router " 
				<< router->get_position() << " just sent the packet from " 
				<< a_flit->get_src_position() << " to " << a_flit->get_dst_position() 
				<< " (time = " << net_clock.get_clock() << ")\n";
		}
		else {
			cout << "[I] Output channel " << pos << " at repeater " 
				<< repeater->get_position() << " just sent the packet from " 
				<< a_flit->get_src_position() << " to " << a_flit->get_dst_position() 
				<< " (time = " << net_clock.get_clock() << ")\n";
		}
	}



	//begin rtg
	/////////////// Congestion Monitor
	if (monitoring &&  (congestion_monitor.back()>0) ) {
		unsigned int len = congestion_monitor.size();
		
		if (congestion_monitor[len-TIME]==net_clock.get_clock()) { // A flit has been sent during this clock cycle
			congestion_monitor[len-BS] -= 1;                      // Do not add a new item, just correct the current occupancy

			if (a_flit->is_tail())
				congestion_monitor[len-FLIT] += 2;
		} 
		else {
			unsigned int prev = congestion_monitor.back();      // Head: 1, Tail: 2, HT:1+2=3

			if (a_flit->is_tail())
				congestion_monitor.push_back(2);
			else
				congestion_monitor.push_back(0);

			congestion_monitor.push_back(net_clock.get_clock());

			//begin rtg
			pPacket p = a_flit->get_packet();
			congestion_monitor.push_back((p->get_src_position()).x);  // source_x
			congestion_monitor.push_back((p->get_src_position()).y);  // source_y
			congestion_monitor.push_back((p->get_dst_position()).x);  // dst_x
			congestion_monitor.push_back((p->get_dst_position()).y);  // dst_y
			congestion_monitor.push_back(p->get_id());                // pkt id
			//end rtg

			congestion_monitor.push_back(prev-1);
		} // else
	} // if
	/////////////// Congestion Monitor
	//end rtg



	pLink link = (pLink) port->get_sink();
	link->receive(a_flit);
	return true;
}



What solution do you recomend?

Sebi
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,657
  • Joined: 23-August 08

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 11:13 AM

You are trying to use the insertion operator, <<, to print something of type struct Position, but C++ doesn't know how to do that. You either need to print a standard data type or provide an overloaded insertion operator in struct Position.
Was This Post Helpful? 0
  • +
  • -

#5 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 01:29 PM

View PostJackOfAllTrades, on 12 November 2011 - 11:13 AM, said:

You are trying to use the insertion operator, <<, to print something of type struct Position, but C++ doesn't know how to do that. You either need to print a standard data type or provide an overloaded insertion operator in struct Position.


Thanks for the reply it shed some light on the problem. I managed to modify the output in a way the compiler agrees with. I'm still getting LNK2001 errors but this time it's different:

channel.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall Channel::switch_granted(void)" (?switch_granted@Channel@@MAE_NXZ)

It now refers to various methods within my classes. Any resolution to this?
Was This Post Helpful? 0
  • +
  • -

#6 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 01:44 PM

Hi,

I am working on a project(VC++ 2008) and stumble upon these errors during build time. I have tried the following change the character type(unicode/ASCII), edited the preprocessor definitions so that it builds as a console app, edited the Runtime Library to all of the available types(/MT, /MTd) with no success.
I am not using any libraries so spotting the actual issue is fairly difficult(at least for myself).
Error message:

channel.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall Channel::switch_granted(void)" (?switch_granted@Channel@@MAE_NXZ)

Every virtual method in the channel class seems to generate such an error.


Does anybody have a solution to such errors(google didn't help me out on this one)?
Many thanks in advance.
Was This Post Helpful? -1
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,657
  • Joined: 23-August 08

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 01:47 PM

Merged duplicate topics.

Stop opening new topics for every error you run into!!!
Was This Post Helpful? 0
  • +
  • -

#8 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 01:55 PM

View PostJackOfAllTrades, on 12 November 2011 - 01:47 PM, said:

Merged duplicate topics.

Stop opening new topics for every error you run into!!!


Sorry I won't (ever) post related topics but the fact is I do not know if I will get a reply(I'm running out of time) and I really need to get the job done.

Sebi
Was This Post Helpful? 0
  • +
  • -

#9 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: error LNK2001: unresolved external symbol

Posted 12 November 2011 - 06:08 PM

> channel.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall Channel::switch_granted(void)" (?switch_granted@Channel@@MAE_NXZ)

Meaning you either did not implement the function switch_granted, or, you did implement it but somehow its not being linked in. That would happen if you didn't add the file with the function to the visual C++ project or something like that.

If you want more help: 1) show us that you do have a definition (i.e. the code) and 2) confirm that it is an actual part of the VC++ project, i.e. not just there in the folder, but there as a file in the project, and that compiler output shows that it is being compiled.

> I am not using any libraries so spotting the actual issue is fairly difficult(at least for myself)

First Google result for LNK2001 (from your own error message): MSDN reference saying the same thing I told you.
Was This Post Helpful? 0
  • +
  • -

#10 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 13 November 2011 - 06:04 AM

I have tried everything mentioned above(added an implementation to every (inherited) method), made sure there are no include files missing yet the problem persists.

I have a Link class that extends a Timer_owner and Connector classes. These look like:

Connector:
  class Connector {
protected:
  class Connector * source;
  class Connector * sink;
  
public:
  void bind_source(class Connector * s) { source = s; }
  void bind_sink(class Connector * s) { sink = s; }
    Connector() { source = sink = 0; }
  Connector(class Connector * src, class Connector * snk) { source = src; sink = snk; }
  
  class Connector * get_source(void) const { return source; }
  class Connector * get_sink(void) const { return sink; }
  virtual ~Connector() {}
  virtual bool can_send(void) const = 0;
  virtual bool can_receive(void) const = 0;
  virtual bool send(void);
  virtual bool receive(class Flit * a_flit) = 0;  
};



Timer_owner:
 class Timer_owner {
protected:
  class Timer timer;
public:
  virtual void timer_fired(void) {};
  Timer_owner(void);
  void init_timer(void) { timer.initialize(); }
  void set_delay(int d) { timer.set_delay(d); }
  virtual ~Timer_owner() {};
};




My link class:
 typedef class Link : public Timer_owner, public Connector {
private:
    int    delay;           // how many clock cycles does it take to tranverse the link
    double e_bit;           // average energy consumption of sending one bit of data

public:
//    Link(int d = 0) { delay = d; source = sink = 0; e_bit = param.link_ebit; }
  Link(class Connector * src, class Connector * dst, int d = 0);
  ~Link(void) {}

  bool can_send(void) const { return source->can_send(); }  // <<< THROWS ERROR
  bool can_receive(void) const { return sink->can_receive(); }
  bool send(void) { return true; }
  bool receive(class Flit * a_flit);

  void set_ebit(double e) { e_bit = e; }
}



The linker cannot resolve the send method.
Was This Post Helpful? 0
  • +
  • -

#11 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: error LNK2001: unresolved external symbol

Posted 13 November 2011 - 09:36 AM

I was able to compile your code without warnings by:

1) Providing a dummy Timer struct in timer_owner.h (the timer_owner code you provided)
2) In link.h, putting includes for timer_owner.h and connector.h (the connector code you provided)
3) Terminating the link class definition with a semicolon
4) Removing the typedef for the link class. What is that "typedef" doing there? Decorative purposes??

5) Creating a link.cpp file, and including link.h in that file.

I'm not seeing any error from your code, assuming you have corresponding aspects in your code (i.e. Timer struct, properly terminated link class).
Was This Post Helpful? 0
  • +
  • -

#12 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 13 November 2011 - 12:15 PM

View PostOler1s, on 13 November 2011 - 09:36 AM, said:

I was able to compile your code without warnings by:

1) Providing a dummy Timer struct in timer_owner.h (the timer_owner code you provided)
2) In link.h, putting includes for timer_owner.h and connector.h (the connector code you provided)
3) Terminating the link class definition with a semicolon
4) Removing the typedef for the link class. What is that "typedef" doing there? Decorative purposes??

5) Creating a link.cpp file, and including link.h in that file.

I'm not seeing any error from your code, assuming you have corresponding aspects in your code (i.e. Timer struct, properly terminated link class).


Under g++ Linux it gave some warnings if I omitted the "typedef". On windows it does not(it has no purpose I know). I've managed to fix the code by making the inherited method in send of void type bool send(void) const = 0; . My total number of errors is now 5(at the beginning there were about 2300 or something like that).

The remaining errors(stil linker errors) are:

network.obj : error LNK2019: unresolved external symbol "bool __cdecl operator==(class Addressee const *,struct Position const &)" (??8@YA_NPBVAddressee@@ABUPosition@@@Z) referenced in function "class std::_Vector_iterator<class Router *,class std::allocator<class Router *> > __cdecl std::_Find<class std::_Vector_iterator<class Router *,class std::allocator<class Router *> >,struct Position>(class std::_Vector_iterator<class Router *,class std::allocator<class Router *> >,class std::_Vector_iterator<class Router *,class std::allocator<class Router *> >,struct Position const &)" (??$_Find@V?$_Vector_iterator@PAVRouter@@V?$allocator@PAVRouter@@@std@@@std@@UPosition@@@std@@YA?AV?$_Vector_iterator@PAVRouter@@V?$allocator@PAVRouter@@@std@@@0@V10@0ABUPosition@@@Z)

I'm guessing tha the "==" operator used to compare vector elements fails because I am comparing something of type Addresse const* with something of type Position const &. I've looked over my network.cpp and network.hpp files but I couldn't find something that makes a comparisson between the types mentioned earlier.

The files from where the error originates from are:
network.hpp
#ifndef NETWORK_HPP
#define NETWORK_HPP


#include "common.hpp"
#include "router.hpp"
#include "link.hpp"
#include "traffic.hpp"

using std::vector;

class Network {
private:
    bool success;

    // configuration parameters
    Topology topology;
    unsigned int n_of_rows;
    unsigned int n_of_cols;
    unsigned int n_of_ports;
    unsigned int n_of_extra_links; // UYO
    unsigned int n_of_switch_ports;
    unsigned int n_of_vcs;

    vector<class Router *> routers;
    vector<class Link *> links;
    vector<class Traffic_source *> sources;
    vector<class Traffic_sink *> sinks;

private:
    void calc_channel_load(void);  // the linker complained about this method
//     void perf_anal_init_lambdas(double * n_lambda);
//     void perf_anal_init_probs(double * n_prob);
    bool overloaded(double * n_lambda);

public:
    void reset(void); 
    Network(void);
    ~Network(void); 
    class Router * get_router(Position & p);
    class Router * get_router(int index) { return routers[index]; } 
    class Traffic_source * get_traffic_source(Position & p);
    class Traffic_source * get_traffic_source(int index) { return sources[index]; }
    class Traffic_sink * get_traffic_sink(Position & p);
    class Traffic_sink * get_traffic_sink(int index) { return sinks[index]; }
    class Link * connect(class Connector * src,  class Connector * dst, int delay=0);

    Topology get_topology(void) const { return topology; }
    vector<class Repeater *> repeaters; // UYO
    unsigned int get_num_of_rows(void) const { return n_of_rows; }
    unsigned int get_num_of_cols(void) const { return n_of_cols; }
    unsigned int get_num_of_ports(void) const { return n_of_ports; }
    unsigned int get_num_of_vcs(void) const { return n_of_vcs; }

    unsigned int get_num_of_traffic_sources(void) const { return sources.size(); }
    unsigned int get_num_of_traffic_sinks(void) const { return sinks.size(); }

    double get_total_injection_rate(void) const;
    
    void tick(void); 
    bool get_success_flag(void) { return success; }
    //    double analyze_latency(void);

    bool dump_equation_file(void);
    bool dump_perf_anal_lib_equation_file(void);
    bool dump_config_file(void);
};

typedef Network *pNetwork;

#endif  // NETWORK_HPP_



Network.cpp
Network::~Network() {
    if (param.verbose) 
        cout<<"[I] removing the whole network..."<<endl;

    // delete all the links in the network
    for (vector<class Router*>::iterator iter=routers.begin(); iter<routers.end(); iter++) 
        delete *iter;

    // delete all the routers in the network
    for (vector<pLink>::iterator iter=links.begin(); iter<links.end(); iter++)
        delete *iter;

    // delete all the traffic sources/sinks in the network
    for (vector<pTraffic_source>::iterator iter=sources.begin(); iter<sources.end(); iter++) 
        delete *iter;
    for (vector<pTraffic_sink>::iterator iter=sinks.begin(); iter<sinks.end(); iter++) 
        delete *iter;
}


// Create a link which connect src and dst with the given delay (default = 0).
// Return the link which is newly created.
pLink Network::connect(class Connector *src, class Connector *dst, int delay) {
    pLink link = new Link(src, dst, delay);
    links.push_back(link);
    src->bind_sink(link);
    // cout <<"Link bound with src \n";
    dst->bind_source(link);
    // cout <<"Link bound with dst: " <<delay <<endl;
    return link;
}


void Network::tick(void) {
    // THE ORDER OF THE FIRING WILL AFFECT THE RESULTS.
//     for (vector<pTraffic_sink>::iterator iter=sinks.begin(); iter<sinks.end(); iter++) 
//         (*iter)->tick();
    for (vector<pTraffic_sink>::iterator iter=sinks.end()-1; iter>=sinks.begin(); iter--) 
      (*iter)->tick();
    for (vector<pTraffic_source>::iterator iter=sources.begin(); iter<sources.end(); iter++) 
      (*iter)->tick();
    for (vector<class Router*>::iterator iter=routers.begin(); iter<routers.end(); iter++) 
      (*iter)->arbiter_tick();
    for (vector<class Router*>::iterator iter=routers.begin(); iter<routers.end(); iter++) 
      (*iter)->in_ports_tick();
    for (vector<class Router*>::iterator iter=routers.begin(); iter<routers.end(); iter++) 
      (*iter)->out_ports_tick();

    // For the repeaters in the LR links
    for (vector<class Repeater*>::iterator iter = repeaters.begin(); iter < repeaters.end(); iter++)  // UYO
      (*iter)->in_ports_tick();
    for (vector<class Repeater*>::iterator iter = repeaters.begin(); iter < repeaters.end(); iter++)  // UYO
      (*iter)->out_ports_tick();
    // For the Flow control algrithm
    for (vector<class Router*>::iterator iter = routers.begin(); iter < routers.end(); iter++) 
      (*iter)->update_prediction();
}


double Network::get_total_injection_rate(void) const {
    double total = 0;
    for (vector<pTraffic_source>::const_iterator iter=sources.begin(); iter<sources.end(); iter++) {
        total += (*iter)->get_total_packet_injection_rate();
    }
    return total;
}


void Network::calc_channel_load(void) {
    pInput_channel ch = 0;

    // first, clear the load parameters of every input channel
    for (vector<class Router*>::iterator r = routers.begin(); r < routers.end(); r++) {
        for (Direction dir = local; dir < invalid_dir; dir=(Direction) (((int) dir) + 1)) {
            ch = (*r)->get_in_channel(dir);
            ch->reset_load();
        }
    }
    // clear the load parameters of every sinks
    for (vector<pTraffic_sink>::iterator iter=sinks.begin(); iter<sinks.end(); iter++) 
        (*iter)->reset_load();

    // now enumerate all the traffic transactions between any source/destination pairs
    for (unsigned int src=0; src<sources.size(); src++) {
        pTraffic_source pts = sources[src];
        for (unsigned int dst=0; dst<sinks.size(); dst++) {
            if (src == dst) 
                continue;
            double load = pts->get_packet_to_destination_rate(dst);
            if (load == 0)
                continue;
            // now let's update all the input channel load used by this traffic 
            Position src_pos = pts->get_position();
            Position dst_pos = sinks[dst]->get_position();

            // first, fill in the local input channel in the local router
            pRouter r = get_router(src_pos);
            ch = r->get_in_channel(local);
            pRouting_engine re = ch->get_routing_engine();
            Direction out_dir = re->decide_direction(src_pos, dst_pos);
            ch->add_load(load, out_dir);

            // now start following the routing path
            Position cur_pos = src_pos;
            pRouter cur_r = r;
            pInput_channel cur_ch = ch;
            while ((cur_pos.x != dst_pos.x) && (cur_pos.y != dst_pos.y)) {
                re = cur_ch->get_routing_engine();
                out_dir = re->decide_direction(src_pos, dst_pos);
                pRouter next_r = cur_r->get_router(out_dir);
                pInput_channel next_ch = next_r->get_in_channel(reverse(out_dir));
                re = next_ch->get_routing_engine();
                out_dir = re->decide_direction(src_pos, dst_pos);
                next_ch->add_load(load, out_dir);

                cur_r = next_r;
                cur_ch = next_ch;
                cur_pos = cur_r->get_position();
            }

            assert((cur_pos.x == dst_pos.x) && (cur_pos.y == dst_pos.y));
            // assert(out_dir == local);
            // finally, we need to update the traffic sinks load
            sinks[dst]->add_load(load);

        }
    }

}



I've included parts which use iterators for I believe that these are the source of the problem.

One more thing:
If I have a class and in it a method that calls a "C" function defined elsewhere(in a separate file, but included in the project) it must be declared as extern no?
Is it enough to declare only the header files in which the "C" function is defined as extern; something like this:
extern "C" {
   #include "SIM_power.h"
   #include "SIM_power_alfs.h"
}


Was This Post Helpful? 0
  • +
  • -

#13 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: error LNK2001: unresolved external symbol

Posted 13 November 2011 - 01:38 PM

Are you using std::find elsewhere in your code? You have a good number of inline functions, so I'm guessing one of the headers makes use of find at some point.

Also, I'm not sure if you realize this, but you don't need to prefix structs and classes with "struct" or "class" when using them. vector<class Repeater*> is not necessary, vector<Repeater*> will do.

> If I have a class and in it a method that calls a "C" function defined elsewhere(in a separate file, but included in the project) it must be declared as extern no?

It must certainly be declared before use. If that C function is being compiled as C code, or you need to prevent name mangling, then extern "C" is required.

> Is it enough to declare only the header files in which the "C" function is defined as extern; something like this:

Is that other function being compiled as C++ or C?
Was This Post Helpful? 0
  • +
  • -

#14 Sebi13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 22-September 11

Re: error LNK2001: unresolved external symbol

Posted 13 November 2011 - 02:25 PM

Quote

Are you using std::find elsewhere in your code? You have a good number of inline functions, so I'm guessing one of the headers makes use of find at some point.

Also, I'm not sure if you realize this, but you don't need to prefix structs and classes with "struct" or "class" when using them. vector<class Repeater*> is not necessary, vector<Repeater*> will do.

> If I have a class and in it a method that calls a "C" function defined elsewhere(in a separate file, but included in the project) it must be declared as extern no?

It must certainly be declared before use. If that C function is being compiled as C code, or you need to prevent name mangling, then extern "C" is required.

> Is it enough to declare only the header files in which the "C" function is defined as extern; something like this:

Is that other function being compiled as C++ or C?


Yes, I am using the std::find method. Do I need to rename it to something else in order for it to work?

> Also, I'm not sure if you realize this, but you don't need to prefix structs and classes with "struct" or "class"

Fixing that right now; I wanted to make sure that the compiler knows exactly what pRouter is(for example).

>Is that other function being compiled as C++ or C?

It is another function compiled as C. So the headers aren't enough no?

This post has been edited by Sebi13: 13 November 2011 - 02:33 PM

Was This Post Helpful? 0
  • +
  • -

#15 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: error LNK2001: unresolved external symbol

Posted 13 November 2011 - 02:41 PM

> Yes, I am using the std::find method. Do I need to rename it to something else in order for it to work?

It's not the name. std::find involves equality comparison, as you can imagine. You said you couldn't find out where the comparison was happening. It's from your usage of std::find, so look at the lines of code involving std::find.

> I wanted to make sure that the compiler knows exactly what pRouter is(for example).

The compiler isn't going to be confused...

> It is another function compiled as C. So the headers aren't enough no?

Then extern C around the headers is sufficient, whenever you use it in a C++ file. Personally, I prefer to do a check for C++ compilation in the header file itself, as opposed to having to wrap extern "C" everytime it gets included.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2