0

I have a problem with merging two projects compiled separately. I created some classes (Qt and C++) to manage two mechanical stages (first project) and one class/interface for a laser scanner (second project). When I import the class/interface in the first project, the compiler gives me a lot of redefinition errors on some Windows api classes (the second project uses classes as winsock2).

Could someone help me to find my error? Not only my "grammatical" errors ;)

Thanks!

Marco Carletti
  • 318
  • 2
  • 5
  • 16
  • Do you use some win api headers? In that case `#include` order does matter:) – undefined May 18 '12 at 10:31
  • In the "stages project" I don't include any header of Windows directly, but in the "laser project" I include two headers of the SDK of the laser: first one includes `winsock2.h` and the second header, in this order, that includes `windows.h`. I read, in another question of the site, that I must include `windows.h` before `winsock2.h`. I tried to correct the headers but the project doesn't compile. – Marco Carletti May 18 '12 at 12:28
  • Don't ask me why, but I excluded `winsock2.h` from the header of the laser SDK. The project is compiled and, for now, it works. I don't understand why, but it works... – Marco Carletti May 18 '12 at 14:37
  • In C++ world weird things occur;) – undefined May 18 '12 at 14:44

1 Answers1

2

Just clean the project, rebuild and run again. One possibility that this may happen is you probably might have used a previous version of library in any of your project and now after merging two projects you may be using latest version of library in other project. The already existing compiled binaries of project which you have merged will be looking for different version of library, but you may have included another version of it in your 2nd project or vice versa!!After merging both appears to be in same project! So try cleaning the Project, use only latest version of library and rebuild and run.

If you try to include both winsock.h and winsock2.h, this error will happen for sure. Because winsock2.h is a complete rewrite of winsock.h. So you would definitely get redefinition errors.

One possible solution is ..

  Try to include winsock2.h before you include the header file(s) which is 
  including winsock.h.That will do.

Or Try using only 1 version of it

ScarCode
  • 3,074
  • 3
  • 19
  • 32
  • I tried to clean and rebuild, but it doesn't work. To "merge" projects, I just put all the .cpp, .h, .lib and .dll files in the same directory of the project. If I compile the project "as is", the compiler builds the project but (obviously) it runs only the part called in the main file. If I include (only include, I don't create any object) my interface class in one of the running project's source code, the compiler gives me errors... The libraries I use is the original libs and dlls of the SDKs, I have only one version of them. – Marco Carletti May 18 '12 at 12:43
  • It's like both projects are working independently and not while merging?? Can you post regarding which library, this redefinition error occurs? and also some errors too? – ScarCode May 18 '12 at 15:17
  • All the errors are like this: `...\include\winsock2.h:1701: error: C2375: 'getsockname': redefinition. Different link.` or this `...\include\winsock2.h:245: error: C2011: 'netent': redefinition type 'struct' C...\include\winsock.h(180): see declaration of 'netent'` – Marco Carletti May 18 '12 at 15:25
  • So that's the problem, You are including both winsock2.h and winsock.h.I have edited my answer, check it out. – ScarCode May 23 '12 at 06:33
  • I include `winsock2.h` in this manner: `#ifndef _WINSOCKAPI_ #include #endif`. Now the project compiles. Thanks! – Marco Carletti Jun 04 '12 at 12:06