Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » header file problem
header file problem [message #24676] Wed, 27 January 2010 05:52 Go to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I am having a problem with a header file.
#ifndef _ConnSock_ConnSock_h_
#define _ConnSock_ConnSock_h_

#include <Web/Web.h>

using namespace Upp;

String Request(const String& r)
{
	Socket s;
	if(!ClientSocket(s, CommandLine().GetCount() ? CommandLine()[0] : "127.0.0.1", 5024)) {
		Cout() << "Unable to connect to server!\n";
		SetExitCode(1);
		return Null;
	}
	s.Write(r + '\n');
	String st = s.ReadUntil('\n');
	Cout() << "st " << st << '\n';
	return s.ReadUntil('\n');
}
#endif

This is from a Socket example. It worked fine as an app.
I removed the main and added the top 2 and the last lines.
My main.cpp has #include "ConnSock.h"
This is the errors:

main.obj : error LNK2019: unresolved external symbol "public: class Upp::String __thiscall Upp::Socket::R
eadUntil(char,int,int)" (?<a href="mailto:ReadUntil@Socket" target="_blank">ReadUntil@Socket</a>@Upp@@QAE?<a href="mailto:AVString@2" target="_blank">AVString@2</a<a href="mailto:>@DHH" target="_blank">>@DHH</a>@Z) referenced in function "class U
pp::String __cdecl Request(class Upp::String const &)" (?Request@@YA?AVString@Upp@@ABV12@@Z)
main.obj : error LNK2019: unresolved external symbol "bool __cdecl Upp::ClientSocket(class Upp::Socket &,
char const *,int,bool,unsigned long *,int,bool)" (?ClientSocket@Upp@@YA_<a href="mailto:NAAVSocket@1" target="_blank">NAAVSocket@1</a>@PBDH_NPAKH2@Z) r
eferenced in function "class Upp::String __cdecl Request(class Upp::String const &)" (?Request@@YA?AV
String@Upp@@ABV12@@Z)
main.obj : error LNK2019: unresolved external symbol "public: int __thiscall Upp::Socket::WriteWait(char
const *,int,int)" (?<a href="mailto:WriteWait@Socket" target="_blank">WriteWait@Socket</a>@Upp<a href="mailto:@@QAEHPBDHH" target="_blank">@@QAEHPBDHH</a>@Z) referenced in function "public: void __thiscal
l Upp::Socket::Write(char const *,int)" (?<a href="mailto:Write@Socket" target="_blank">Write@Socket</a>@Upp<a href="mailto:@@QAEXPBDH" target="_blank">@@QAEXPBDH</a>@Z)
C:\upp\out\MSC9.Debug.Debug_full.Gui\Neilson1.exe : fatal error LNK1120: 3 unresolved externals

It has been several years since I worked with C++.
I don't know if this is a basic C++ problem or if it is specific to U++.

edit: I created a directory under c:\upp\Neilson and have Neilson1 and SocketClient. When I pull up SocketClient it works fine. When I pull up Neilson1 that app works fine until #include "ConnSock.h" is added. TheIDE sees the ConnSock.h
Since the externals work with SocketClient.cpp it must be something wrong with my ConnSock.h code.

[Updated on: Wed, 27 January 2010 06:15]

Report message to a moderator

Re: header file problem [message #24677 is a reply to message #24676] Wed, 27 January 2010 07:36 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

I haven't such problem
Try package.

Best regards,
Anton

P.S. Don't store your projects in Ultimate++ directory. If you reinstall U++ you lose those projects. Use MyApps-directory.
  • Attachment: ConnSock.rar
    (Size: 0.80KB, Downloaded 193 times)

[Updated on: Wed, 27 January 2010 07:44]

Report message to a moderator

Re: header file problem [message #24678 is a reply to message #24677] Wed, 27 January 2010 09:09 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Your problem seems to be that you did not add the correct packages to your main package. You should have Core and Web added.

Also, having implementations in header files is not a good idea because you can get ugly link error in the long run.
Re: header file problem [message #24680 is a reply to message #24677] Wed, 27 January 2010 09:15 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks for the help Anton.

I downloaded the ConnSock.rar, inzipped it and tried it without any changes. I get these errors:

main.obj : error LNK2019: unresolved external symbol "public: class Upp::String __thiscall Upp::Socket::R
eadUntil(char,int,int)" (?<a href="mailto:ReadUntil@Socket" target="_blank">ReadUntil@Socket</a>@Upp@@QAE?<a href="mailto:AVString@2" target="_blank">AVString@2</a<a href="mailto:>@DHH" target="_blank">>@DHH</a>@Z) referenced in function "class U
pp::String __cdecl Request(class Upp::String const &)" (?Request@@YA?AVString@Upp@@ABV12@@Z)
main.obj : error LNK2019: unresolved external symbol "bool __cdecl Upp::ClientSocket(class Upp::Socket &,
char const *,int,bool,unsigned long *,int,bool)" (?ClientSocket@Upp@@YA_<a href="mailto:NAAVSocket@1" target="_blank">NAAVSocket@1</a>@PBDH_NPAKH2@Z) r
eferenced in function "class Upp::String __cdecl Request(class Upp::String const &)" (?Request@@YA?AV
String@Upp@@ABV12@@Z)
main.obj : error LNK2019: unresolved external symbol "public: int __thiscall Upp::Socket::WriteWait(char
const *,int,int)" (?<a href="mailto:WriteWait@Socket" target="_blank">WriteWait@Socket</a>@Upp<a href="mailto:@@QAEHPBDHH" target="_blank">@@QAEHPBDHH</a>@Z) referenced in function "public: void __thiscal
l Upp::Socket::Write(char const *,int)" (?<a href="mailto:Write@Socket" target="_blank">Write@Socket</a>@Upp<a href="mailto:@@QAEXPBDH" target="_blank">@@QAEXPBDH</a>@Z)
C:\upp\out\MSC9.Debug.Debug_full\ConnSock.exe : fatal error LNK1120: 3 unresolved externals


That is strange since this code runs fine in the same directory.
#include <Web/Web.h>

using namespace Upp;

String Request(const String& r)
{
	Socket s;
	if(!ClientSocket(s, CommandLine().GetCount() ? CommandLine()[0] : "127.0.0.1", 5024)) {
		Cout() << "Unable to connect to server!\n";
		SetExitCode(1);
		return Null;
	}
	s.Write(r + '\n');
	String st = s.ReadUntil('\n');
	Cout() << "st " << st << '\n';
	return s.ReadUntil('\n');
}

CONSOLE_APP_MAIN
{
	Cout() << Request("+") << '\n';
	Cout() << Request("33") << '\n';
}


The "+" gets the location from another app (Nww) and returns the Latitude and Longitude (35.037613000,-117.968790000). All of my interaction with the Nww app is through a socket, GPS tracking, distance calculations with Vincenty, etc. I used Java before but am now porting to C++.

When I get something to work I copy it to a different location.

[Updated on: Wed, 27 January 2010 09:37]

Report message to a moderator

Re: header file problem [message #24684 is a reply to message #24680] Wed, 27 January 2010 09:29 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
Thanks cbpporter.

I have:
#include <CtrlLib/CtrlLib.h>
#include "ConnSock.h"
#include <Web/Web.h>

using namespace Upp;

#define LAYOUTFILE <Neilson1/dlg.lay>
#include <CtrlCore/lay.h>

"having implementations in header files is not a good idea"
How should that be done?
  • Attachment: Neilson1.zip
    (Size: 2.16KB, Downloaded 188 times)
Re: header file problem [message #24686 is a reply to message #24678] Wed, 27 January 2010 10:02 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
cbpporter wrote on Wed, 27 January 2010 09:09

Your problem seems to be that you did not add the correct packages to your main package. You should have Core and Web added.


Thanks cbpporter!

Remember I am a noob to U++.

I looked at the upper left corner of TheIDE and noticed the one that worked has "Web". The ones that did not work did not have it.

I added "Web" and it links without error.

Thanks again but you could be a little more explicit to us noobs.
Re: header file problem [message #24691 is a reply to message #24686] Wed, 27 January 2010 10:33 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Sorry about that. It is hard to determine what level of detail to give. I varies from person to person.

But working with packages is both very easy and very confusing for U++ newcomers. Yet it is a central part of U++, and you absolutely need to learn the basics.

Something learned the hard way is still learned Smile.

Since you come from come from a Java background, it is easy to compare a package to a .jar. A nest is simply a folder where you have more JARs/packages. All the nests that you are using to get a binary is called an assembly, but is very similar to the classpath from Java.

So if you call your package "Foo" and want to do what you did in that code, Foo will need Core and Web. When you add Core, it will automatically add the dependencies, in this case "plugin/z". When you add Web, it will add the dependencies again. Web depends on Core, but you already have it, so it won't be added again. You could have added Web directly, and it would have pulled in Core.

Because you included the header for these packages it compiled because it found the declaration of the items you were using. But when linking, because Web was not added, you basically "had Web.jar missing from your classpath. The classloader failed". I hope I did not confuse you more with my Java metaphor.

Re: header file problem [message #24697 is a reply to message #24691] Wed, 27 January 2010 13:14 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
cbpporter wrote on Wed, 27 January 2010 10:33

... an assembly, but is very similar to the classpath from Java.

you basically "had Web.jar missing from your classpath.



I appreciate your explaining this. In Java using Eclipse the classpath is set in the IDE in a different way.

I got it so clicking Points->Get Point 1 (and Point 2) returns the correct location from the Nww app and displays in the Point 1 and Point 2 text boxes.

I have several other .java files I will be porting to C++ .h files, parse, format fixed setPrecision, deg min sec, GotTo, GPS tracking, calculate distance and direction, etc.

I appreciate getting this header file problem worked out and info on how the "classpath" is handled in TheIDE.

Thank you cbpporter!!!
index.php?t=getfile&id=2176&private=0
  • Attachment: GuiC++.jpg
    (Size: 40.26KB, Downloaded 425 times)

[Updated on: Wed, 27 January 2010 13:44]

Report message to a moderator

Previous Topic: upp 1875 + Ubuntu 9.10
Next Topic: Using U++ with existing code
Goto Forum:
  


Current Time: Thu Mar 28 10:50:22 CET 2024

Total time taken to generate the page: 0.01321 seconds