Author Topic: winapi under linux  (Read 13048 times)

Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
winapi under linux
« on: June 16, 2010, 03:35:28 pm »
Hello,


I am using CodeBlocks in a Ubuntu. However, I want to be able to compile windows libraries/applications. Therefore I downloaded the windows api from this source:
http://sunet.dl.sourceforge.net/project/mingw/MinGW/BaseSystem/RuntimeLibrary/Win32-API/w32api-3.14/w32api-3.14-mingw32-dev.tar.gz

I extracted the archive to a folder, I created, and added <myfolder>/include to the "Search Directories" in Settings->Compiler and Debugger...

Now, when I am compiling a file including <windows.h>, i get the following errors:

/usr/include/bits/time.h|69|error: redefinition of ‘struct timeval’|
/data/Programmierung/WinAPI/include/winsock2.h|109|error: previous definition of ‘struct timeval’|
/usr/include/sys/select.h|78|error: conflicting declaration ‘typedef struct fd_set fd_set’|
/data/Programmierung/WinAPI/include/winsock2.h|64|error: ‘fd_set’ has a previous declaration as ‘typedef struct fd_set fd_set’|
/usr/include/sys/select.h|112|error: declaration of C function ‘int select(int, fd_set*, fd_set*, fd_set*, timeval*)’ conflicts with|
/data/Programmierung/WinAPI/include/winsock2.h|632|error: previous declaration ‘int select(int, fd_set*, fd_set*, fd_set*, const timeval*)’ here|
||=== Build finished: 6 errors, 0 warnings ===|


I guess this is a general problem, with a common solution. Even though I can't solve it, because I do not understand it in depth. I think the errors mean, that the standard library somehow is dependent on the api of the operating system. Does this mean that I have to install a different version of the c++ standard library for every platform I want to compile for?

Nice Greetings

sg

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: winapi under linux
« Reply #1 on: June 16, 2010, 03:39:22 pm »
Search for "cross compiler" in Google. That should give you plenty of answers and ways to proceed. There have been some threads here mentioning it as well, so it may be a good search for this forum as well.

Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: winapi under linux
« Reply #2 on: June 16, 2010, 03:51:53 pm »
thanks for your quick reply.
Next Question: Why don't I have to manually set a search path for the standard library if I use gcc? Codeblocks seems to know that it is placed under /usr/include/. But how?

Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: winapi under linux
« Reply #3 on: June 16, 2010, 05:39:15 pm »
I have read much about cross compiling and stuff. My Problem remains the same.

How can I avoid redefinition of the symbols? What is the reason for it?

This question is not answered by any explanation on cross compiling I read.

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
« Last Edit: June 16, 2010, 07:45:08 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: winapi under linux
« Reply #5 on: June 16, 2010, 10:52:36 pm »
I have read anything about cross compiling now. 2 general questions:

1. The first thing would be to know, if I can prevent codeblocks/gcc to automatically include /usr/include/ even if it is not in the search directories list.

2. I guess the only difference between compiling for a pc running Windows and one running Linux is inclusion of the correct headers and libraries. Is this right?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: winapi under linux
« Reply #6 on: June 17, 2010, 07:58:29 am »
I have read anything about cross compiling now. 2 general questions:

1. The first thing would be to know, if I can prevent codeblocks/gcc to automatically include /usr/include/ even if it is not in the search directories list.

2. I guess the only difference between compiling for a pc running Windows and one running Linux is inclusion of the correct headers and libraries. Is this right?

You obviously did either not read anything about cross-compiling or you did not understand what it means.
1. no need to, use i586-mingw32msvc-gcc (or something similar) instead, packages exist for most major distros as far as I know,

2. no

Read this carefully: http://forums.codeblocks.org/index.php/topic,3343.0.html
and especially if you want to use wxwidgets in cross-compiling read this wiki article:
http://wiki.codeblocks.org/index.php?title=Cross_Compiling_wxWidgets_Applications_on_Linux
and this thread: http://forums.codeblocks.org/index.php/topic,7978.0.html



Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: winapi under linux
« Reply #7 on: June 18, 2010, 01:06:48 am »
Thank you for your patience.
I think I got it now.

One more thing on question 1.: So a the compilers executable automatically searches for standard headers to include in ./../include?
Therefore when installing MinGW one has to add ./../i586-mingw32msvc/include to the "Search Directories" List. I am quite sceptic about this behavior. How does the compiler know, that this headers should replace the standard library headers that it otherwise would expect to be at ./../include/, and not include both of them?
  Please excuse that I am insisting on this point. I am just asking to get a more profound understanding, not to go on anyones nerves.

I installed mingw. And I managed to get rid of the library conflicts... At last I am able to compile my project using mingw now.

3. What do I have to do to make it produce a .dll file? Is it enough to rename the output filename to *.dll instead of *.exe? But still it does not produce a .lib file then... How to do that?
« Last Edit: June 18, 2010, 01:08:51 am by Samuel G. »

Offline kencamargo

  • Multiple posting newcomer
  • *
  • Posts: 110
Re: winapi under linux
« Reply #8 on: June 18, 2010, 03:57:44 am »
Therefore when installing MinGW one has to add ./../i586-mingw32msvc/include to the "Search Directories" List. I am quite sceptic about this behavior. How does the compiler know, that this headers should replace the standard library headers that it otherwise would expect to be at ./../include/, and not include both of them?

Read carefully the instructions, everything you need is there. This kind of setting is handled by wx-config, see the item under the heading "Fixing build options" in http://wiki.codeblocks.org/index.php?title=Cross_Compiling_wxWidgets_Applications_on_Linux, as already recommended.

Quote
3. What do I have to do to make it produce a .dll file? Is it enough to rename the output filename to *.dll instead of *.exe? But still it does not produce a .lib file then... How to do that?

Start your project as a shared library.

Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: winapi under linux
« Reply #9 on: June 18, 2010, 11:54:50 am »
3. Sorry, *.dll, instead of *.so, I mean. My Project is a shared library project, but still mingw-gcc only outputs a .dll, but no .lib file.
This are the command line options:
Quote
-------------- Build: Debug in sgCommon ---------------

i586-mingw32msvc-g++ -shared -L/usr/i586-mingw32msvc/lib  obj/Windows/Debug/Source/UnitGlobal.o obj/Windows/Debug/Source/UnitManager.o obj/Windows/Debug/Source/UnitSGCommon.o obj/Windows/Debug/Source/UnitTimer.o obj/Windows/Debug/sgDataStructure/Source/UnitGlobal.o obj/Windows/Debug/sgDataStructure/Source/UnitList.o obj/Windows/Debug/sgDataStructure/Source/UnitListBase.o obj/Windows/Debug/sgDataStructure/Source/UnitListElement.o obj/Windows/Debug/sgDataStructure/Source/UnitListElementPointer.o obj/Windows/Debug/sgDataStructure/Source/UnitPointerList.o obj/Windows/Debug/sgDataStructure/Source/UnitPointerListBase.o obj/Windows/Debug/sgDataStructure/Source/UnitPointerTree.o obj/Windows/Debug/sgDataStructure/Source/UnitPointerTreeBase.o obj/Windows/Debug/sgDataStructure/Source/UnitPointerTreeElement.o obj/Windows/Debug/sgDataStructure/Source/UnitSGDataStructure.o obj/Windows/Debug/sgDataStructure/Source/UnitTree.o obj/Windows/Debug/sgDataStructure/Source/UnitTreeBase.o obj/Windows/Debug/sgDataStructure/Source/UnitTreeElement.o obj/Windows/Debug/sgException/Source/UnitException.o obj/Windows/Debug/sgException/Source/UnitGlobal.o obj/Windows/Debug/sgException/Source/UnitSGException.o obj/Windows/Debug/sgException/Source/UnitTextException.o obj/Windows/Debug/sgException/Source/UnitTypeException.o obj/Windows/Debug/sgGlobal/Source/UnitGlobal.o obj/Windows/Debug/sgGlobal/Source/UnitPreprocessor.o obj/Windows/Debug/sgGlobal/Source/UnitSGGlobal.o obj/Windows/Debug/sgGlobal/Source/UnitTemplateAbstraction.o obj/Windows/Debug/sgGlobal/Source/UnitWrapper.o obj/Windows/Debug/sgMath/Source/UnitGlobal.o obj/Windows/Debug/sgMath/Source/UnitMath.o obj/Windows/Debug/sgMath/Source/UnitNumber.o obj/Windows/Debug/sgMath/Source/UnitSGMath.o obj/Windows/Debug/sgMemory/Source/UnitAutoPointer.o obj/Windows/Debug/sgMemory/Source/UnitGlobal.o obj/Windows/Debug/sgMemory/Source/UnitMemory.o obj/Windows/Debug/sgMemory/Source/UnitMemoryFunctions.o obj/Windows/Debug/sgMemory/Source/UnitMemoryManager.o obj/Windows/Debug/sgMemory/Source/UnitSGMemory.o obj/Windows/Debug/sgStream/Source/UnitFile.o obj/Windows/Debug/sgStream/Source/UnitGlobal.o obj/Windows/Debug/sgStream/Source/UnitInFile.o obj/Windows/Debug/sgStream/Source/UnitInStream.o obj/Windows/Debug/sgStream/Source/UnitMessageBox.o obj/Windows/Debug/sgStream/Source/UnitOutFile.o obj/Windows/Debug/sgStream/Source/UnitOutStream.o obj/Windows/Debug/sgStream/Source/UnitReport.o obj/Windows/Debug/sgStream/Source/UnitReportFile.o obj/Windows/Debug/sgStream/Source/UnitReportFunctions.o obj/Windows/Debug/sgStream/Source/UnitReportManager.o obj/Windows/Debug/sgStream/Source/UnitReportMessageBox.o obj/Windows/Debug/sgStream/Source/UnitReportStream.o obj/Windows/Debug/sgStream/Source/UnitReportStreamManager.o obj/Windows/Debug/sgStream/Source/UnitSGStream.o obj/Windows/Debug/sgStream/Source/UnitStream.o obj/Windows/Debug/sgStream/Source/UnitStreamManager.o obj/Windows/Debug/sgString/Source/UnitGlobal.o obj/Windows/Debug/sgString/Source/UnitSGString.o obj/Windows/Debug/sgString/Source/UnitString.o obj/Windows/Debug/sgString/Source/UnitStringFunctions.o obj/Windows/Debug/sgTypes/Source/UnitGlobal.o obj/Windows/Debug/sgTypes/Source/UnitListHeterogeneous.o obj/Windows/Debug/sgTypes/Source/UnitListType.o obj/Windows/Debug/sgTypes/Source/UnitSGTypes.o obj/Windows/Debug/sgTypes/Source/UnitTypeTraits.o   -o Bin/Debug/sgCommon.dll -lstdc++  -lwinmm
Output size is 4,14 MB
Running target post-build steps
cp --preserve=timestamps Bin/Debug//libsgCommon.a Bin/Debug//../Lib/libsgCommon.a
cp: Aufruf von stat für „Bin/Debug//libsgCommon.a“ nicht möglich: No such file or directory
Process terminated with status 1 (0 minutes, 2 seconds)
0 errors, 0 warnings

The article you mentioned is good. Everything is configured as described there. The wxWidgets settings don't help me, because I don't use wxWidgets in this project.

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: winapi under linux
« Reply #10 on: June 18, 2010, 01:53:15 pm »
3. Sorry, *.dll, instead of *.so, I mean. My Project is a shared library project, but still mingw-gcc only outputs a .dll, but no .lib file.
This are the command line options:
Quote
-------------- Build: Debug in sgCommon ---------------

Running target post-build steps
cp --preserve=timestamps Bin/Debug//libsgCommon.a Bin/Debug//../Lib/libsgCommon.a
cp: Aufruf von stat für „Bin/Debug//libsgCommon.a“ nicht möglich: No such file or directory
Process terminated with status 1 (0 minutes, 2 seconds)
0 errors, 0 warnings

The article you mentioned is good. Everything is configured as described there. The wxWidgets settings don't help me, because I don't use wxWidgets in this project.

MinGW GCC does NOT produce .lib files; MSVC and other windows compilers produce .lib files.

Your post builds steps are not working; assume all relative paths are relative to project file location.

Tim S.
« Last Edit: June 18, 2010, 01:54:48 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Samuel G.

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: winapi under linux
« Reply #11 on: June 18, 2010, 05:58:52 pm »
Jes, I forgot that this mechanism is called .a under gcc, not .lib. Sorry I have got confused about all this stuff.
So again: how to generate a .a as part of a DLL-Project?
It is just a pitty that there is no Project template for creating DLLs in Codeblocks for ubuntu. And I didn't find any documents on how to resemble the necessary settings by hand.
[of course my post build steps don't work, because they expect a .a file in the output]

Online stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: winapi under linux
« Reply #12 on: June 18, 2010, 06:17:50 pm »

The command used under Windows MinGW GCC DLL build.
Quote
mingw32-g++.exe -shared -Wl,--output-def=bin\Debug\libTest.dll.def -Wl,--out-implib=bin\Debug\libTest.dll.a -Wl,--dll  obj\Debug\main.o   -o bin\Debug\Test.dll  -luser32
Creating library file: bin\Debug\libTest.dll.a

NOTE: You really need to find a support site for your questions other than Code::Blocks Website; Your questions are compiler related in nearly all cases.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: winapi under linux
« Reply #13 on: June 18, 2010, 07:56:02 pm »
It is just a pitty that there is no Project template for creating DLLs in Codeblocks for ubuntu. And I didn't find any documents on how to resemble the necessary settings by hand.
What about the shared library template?

http://www.linuxforums.org/forum/coffee-lounge/37811-does-linux-use-dlls.html
Quote
Yes linux does use dll's, however the name dll isn't a generic computer science term it's just what windows calls it, it's a function library and in linux they're called libraries and pretty much always have the postfix of .so.

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]