Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 207 208 [209] 210 211 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886650 times)

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3120 on: October 18, 2012, 06:29:42 am »

You can but you have to have the library built for that (or just put the library sources in your project and build all together)
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3121 on: October 18, 2012, 07:35:25 am »

Yeah, I did that last thing, defined the necessary defines in the top of the files (it's just a .h and .c), and it compiles fine, but I still get a linker error about "undefined reference to function triangulate(<params here>). I do get the .o file, though.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3122 on: October 18, 2012, 08:32:29 am »

Yeah, I did that last thing, defined the necessary defines in the top of the files (it's just a .h and .c), and it compiles fine, but I still get a linker error about "undefined reference to function triangulate(<params here>). I do get the .o file, though.

Make sure that, when using a C header in C++ code, you do the following:

Code: [Select]
extern "C" {
#include "c_header.h"
}

I don't know if that will fix your linker problem, but it's worth a shot.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3123 on: October 18, 2012, 09:14:25 am »

Okay, thirty minutes of fruitless trial and error.

Can someone help? D:

I get these errors:

Quote
1>main.obj : error LNK2005: "public: virtual int __thiscall GenericObject::draw(class TCODConsole *)" (?draw@GenericObject@@UAEHPAVTCODConsole@@@Z) already defined in Engine.obj
1>main.obj : error LNK2005: "public: virtual int __thiscall Cursor::draw(class TCODConsole *)" (?draw@Cursor@@UAEHPAVTCODConsole@@@Z) already defined in Engine.obj
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Engine.obj : error LNK2001: unresolved external symbol "struct PODS POD" (?POD@@3UPODS@@A)

Relevant files:
Spoiler: Engine.cpp (click to show/hide)
Spoiler: PODS.h (click to show/hide)
Spoiler: Baseclass.h (click to show/hide)
Spoiler: main.cpp (click to show/hide)

From what I can see, the draw functions are somehow defined twice. I don't see how.
I also can't see why PODS POD is unresolved, when it's in both main and everywhere as extern. I'm kinda frustrated, since there was a "left of . must be a function" sort of error that I didn't know what was the cause, nor the cure. It disappeared sometime.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3124 on: October 18, 2012, 09:14:55 am »

Double post.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3125 on: October 18, 2012, 09:45:57 am »

The 2005's are caused by putting those function definitions in the .h file. It doesn't like it when the .h has both the function declaration in the class definition and the function definition. Move those 2 functions to a .cpp which includes that .h file.
« Last Edit: October 18, 2012, 09:55:26 am by alway »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3126 on: October 18, 2012, 09:49:22 am »

Weird...  ??? Do all functions do that, or is that a special case? I'm sure I've defined and declared a function in a single .h file more than once...
BTW, I'm not at my PC, so I'll have to get back on that in about 16 hours xD

Also, any help on the extern POD PODS error? Dx
C++'s incomprehensible errors are the worst.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3127 on: October 18, 2012, 09:56:09 am »

That's something member functions do; if you are using a more c-like syntax without putting things in classes, it works just fine.

As for the 2001 error, I don't think you are using extern correctly. From what I recall, extern says 'there is some variable with this name which is in the global scope of another file.' Which requires there to be a 'PODS POD;' in the global scope of another file (a .cpp in particular, IIRC). If one doesn't exist without an 'extern' marker, the linker then gets confused, as it's looking for a non-extern version to use as sort of the master-variable all of them are set to. If you remove 'extern' from the version in main, I suspect that error would go away, assuming I remember how they work correctly.

Edit: seems I don't recall correctly; may be something else.
Edit2: seems I do recall correctly; set up similar test code, got the same error, then fixed it by removing the 'extern' from the declaration in main.

The test code:
Code: ("cla.cpp") [Select]
#include "stru.h"

extern stru s;
Code: ("stru.h") [Select]
struct stru
{
int n;
char* str;
};
Code: ("main.cpp") [Select]
#include "stru.h"
#include <iostream>
using namespace std;

extern stru s;

int main()
{
cout<<s.n<<endl;
return 0;
}
This throws LNK2001 error; remove the 'extern' from one of the two 'stru s,' and the errors go away, while leaving the 2 'stru s' as the same variable (verified by a function in cla.cpp changing its value; not shown).
« Last Edit: October 18, 2012, 10:32:14 am by alway »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3128 on: October 18, 2012, 11:32:33 am »

Yeah, I did that last thing, defined the necessary defines in the top of the files (it's just a .h and .c), and it compiles fine, but I still get a linker error about "undefined reference to function triangulate(<params here>). I do get the .o file, though.

Make sure that, when using a C header in C++ code, you do the following:

Code: [Select]
extern "C" {
#include "c_header.h"
}

I don't know if that will fix your linker problem, but it's worth a shot.
*D'OH*
Thanks.

Skyrunner, i think it's because you redefine POD in the main. Try removing PODS POD from the main function, and the extern from the global declaration before that.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3129 on: October 18, 2012, 12:47:32 pm »

I need some help understanding build options in CodeBlocks related to the linker. I have two projects: Hello World and TestLibrary, and I want to link TestLibrary with Hello world.

In Search directories --> Linker, I put "..\lib\", and in Linker settings --> Link libraries: I put "TestLibrary". I get a compile error: "cannot find -lTestLibrary".

However, if I don't put anything in Search directories --> Linker, and put the full path of the library in Linker settings --> Link libraries: ("..\lib\TestLibrary.a"), it works fine.

I've tried lots of things, like changing "TestLibrary" to "TestLibrary.a" in the first case. Can anyone explain what's going on?
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3130 on: October 18, 2012, 01:30:27 pm »

I need some help understanding build options in CodeBlocks related to the linker. I have two projects: Hello World and TestLibrary, and I want to link TestLibrary with Hello world.

In Search directories --> Linker, I put "..\lib\", and in Linker settings --> Link libraries: I put "TestLibrary". I get a compile error: "cannot find -lTestLibrary".

However, if I don't put anything in Search directories --> Linker, and put the full path of the library in Linker settings --> Link libraries: ("..\lib\TestLibrary.a"), it works fine.

I've tried lots of things, like changing "TestLibrary" to "TestLibrary.a" in the first case. Can anyone explain what's going on?

Try naming the library file "libTestLibrary.a". When you specify a library as "a", ld (GCC's linker) looks for a file named "liba.a". Specifying the full path in the library list makes it override that behavior and look for the exact file you gave it.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3131 on: October 18, 2012, 01:34:43 pm »

That worked! I used "..\lib" and "libTestLibrary" in the build options. Thanks.


Edit: Does this mean that I can only use the Search directories for the linker if the '.a's are prefixed with "lib"?
« Last Edit: October 18, 2012, 01:37:10 pm by dreadmullet »
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3132 on: October 18, 2012, 08:44:56 pm »

Whoa... I spent the good chunk of a few days trying to get Qt to work properly with Visual Studio. Bad idea. I could get the basics of a window, but I couldn't get buttons to work with Qt's complex build system. So I discovered that CodeBlocks has a Qt4 project template, and I created a new project with that and took 2 minutes to set it up, and it worked perfectly and built instantly. Why did I ever doubt CodeBlocks...

This has happened to me so many times with Visual Studio. I try to get some library working that was originally made for Linux. But then it takes me days to figure it out, or most of the time I give up after hours of googling. I think I'll switch to CodeBlocks and MinGW from now on.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3133 on: October 18, 2012, 09:13:31 pm »

Blurg. I guess writing thorough unit tests for my shit is good. In java, the supplementary collections returned by the methods of collections do not use their parent classes methods! but directly deal wit the underlying data structures.

What this means is that calling MyCustomCollection.keySet().remove(key) DOES NOT call MyCustomCollection.remove(key)... so any logic you have to perform when removing something from your collection? gets shit on. You have to create an inner class to handle each of these collections f you have special logic that must execute on insert/removal.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3134 on: October 18, 2012, 09:31:48 pm »

Why do you have both collatznumber and collatzednumber? collatznumber is read in from standard input, has its value assigned to collatzednumber, and then is never used again. You can combine those two variables into one.

Kept the rest of the post in mind and used it all, but this I was confused about for a bit before I remembered that I wanted to write a program that will do the collatz process on every number up until a number of the user's choosing and, at the end, output the number that took the longest to collatz. Naturally, that would probably require an entirely rewritten program, so the "collatznumber" variable is kind of a zombie :P
Pages: 1 ... 207 208 [209] 210 211 ... 796