Thread: LwIP issue: "undefined reference".

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    6

    Exclamation LwIP issue: "undefined reference".

    Hi, I'm working on a project for school that will be using lwIP, and I need to familiarize myself with how it works. For now I'm just trying to write a simple test program. It doesn't even do anything yet, but I cannot for the life of me get it to compile:
    Code:
    #include "lwip\udp.h"
    
    void udp_packet_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
    
    main(){
    	// Create a new pcb.
    	struct udp_pcb * pcb;
    	pcb = udp_new();
    	if (pcb == NULL)
    		return -1;
    
    	// Bind to any IP on port 60,000.
    	if (udp_bind(pcb, IP_ADDR_ANY, 60000) != ERR_OK)
    		return -2;
    
    	// On datagram receipt, call udp_packet_recv.
    	udp_recv(pcb, udp_packet_recv, NULL);
    }
    
    void udp_packet_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port){
    	if (p != NULL){
    		// TODO: Case handling GET packet.
    		// TODO: Case handling data receipt.
    	
    		pbuf_free(p); // Free pbuf when finished.
    	}
    }
    Every time I try to compile this, I get the following errors:

    Code:
    C:\Users\ZACHAR~1\AppData\Local\Temp\cc1kZ7BP.o:client.c:(.text+0xf): undefined reference to `udp_new()'
    
    C:\Users\ZACHAR~1\AppData\Local\Temp\cc1kZ7BP.o:client.c:(.text+0x3d): undefined reference to `udp_bind(udp_pcb*, ip_addr*, unsigned short)'
    
    C:\Users\ZACHAR~1\AppData\Local\Temp\cc1kZ7BP.o:client.c:(.text+0x5d): undefined reference to `udp_packet_recv(void*, udp_pcb*, pbuf*, ip_addr*, unsigned short)'
    
    C:\Users\ZACHAR~1\AppData\Local\Temp\cc1kZ7BP.o:client.c:(.text+0x69): undefined reference to `udp_recv(udp_pcb*, void (*)(void*, udp_pcb*, pbuf*, ip_addr*, unsigned short), void*)'
    
    C:\Users\ZACHAR~1\AppData\Local\Temp\cc1kZ7BP.o:client.c:(.text+0x8e): undefined reference to `pbuf_free(pbuf*)'
    
    collect2: ld returned 1 exit status
    I read something online about linking "lwip4", but have not been able to find anything about that file elsewhere. (I can't even figure out where I originally read that...) I believe I've included all the requisite files!
    http://i20.photobucket.com/albums/b2...hots/files.png
    I'm using "lwip-win32-msvc-0.1", which is based on the CVS version of lwIP from 23-01-2002. It is available for download here: lwip-win32-msvc-0.1.zip - 免费高速下载 - 共享资料

    The computer I am attempting to compile on is a Sony VPCF126FM, with no hardware modifications of any kind: http://www.docs.sony.com/release/spe...26FMB_mksp.pdf

    I'm using MiniGW command line " g++ client.c -o client.exe" to compile. (Nothing fancy.)
    Can anybody help me out here? This has become a real sticking point.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    That command line is conspicuously missing -l<name of library goes here>.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    I managed to find "lwip4.dsp" and "lwip4.dsw" in the "lwip-win32-msvc-0.1\proj\msvc6" directory. I'm not sure these are the right files though, and attempting to link them with the following commands has not worked.

    Code:
    -llwip4.dsp
    -llwip4.dsw
    
    -l lwip4.dsp
    -l lwip4.dsw
    
    -llwip4
    -l lwip4
    I keep getting some variation of "ld.exe: cannot find -llwip4".

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    .dsp and .dsw aren't libraries. They are, if I recall correctly, Visual Studio's internal project file format from version 6 or something. Your libraries will end in .lib or .dll (or possibly .a or .so).

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    Yeah, I kinda figured that from the parts of the .dsp file I was able to read.. but I can't find any other files by the name of "lwip4", either in the package I'm using or on the internet.

    Anybody have any ideas as to where I might find a library that fits the bill?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by DaMunky89 View Post
    Yeah, I kinda figured that from the parts of the .dsp file I was able to read.. but I can't find any other files by the name of "lwip4", either in the package I'm using or on the internet.

    Anybody have any ideas as to where I might find a library that fits the bill?
    If the package you're using doesn't have any .lib or .dll files at all, then you either downloaded source-code-only (which makes it your responsibility to make the library and/or put the code in your own project) or you got a bad download.

    There is also no reason in the world that your library has to be called lwip4.lib or lwip4.dll.

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    6
    Yeah.. I found people talking on that Chinese site about lwip-win32-msvc-0.1, somehow using the .dsp and .dsw file to compile the .lib using Visual Basic 6? So it seems like this download is source-only. Next I'm going to try and figure compiling the lib myself I guess.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "undefined reference" in my Class
    By bumcheekcity in forum C++ Programming
    Replies: 8
    Last Post: 04-08-2007, 01:40 PM
  2. Replies: 5
    Last Post: 06-01-2006, 04:37 PM
  3. Replies: 11
    Last Post: 12-14-2005, 02:09 AM
  4. "Undefined Reference"
    By crepincdotcom in forum C Programming
    Replies: 24
    Last Post: 05-31-2004, 05:12 PM
  5. TAPI "undefined reference"
    By Sebastiani in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-16-2002, 08:16 PM