0

I am refactoring an old Borland C/C++98 program. I would like to program it under linux platform but to beginning, as I have severals additionnals boards, I clean the program, remove all GUI OWL and make tests under win7 and mingw64 to use modern gcc/g++.

I actually try to link a sample code that use C320 turbo Moxa multiport serial board. As mentionned in http://www.mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use it should link .lib and .dll.

So I tried to link my sample with Moxa PComm.lib for sio_open, sio_read, sio_write… functions as

g++ -m32 -Wall -std=c++14 src/main.cpp src/rs232_c320t.cpp … -L./lib -lPComm

and it returns

./lib/PComm.lib: file not recognized: File format not recognized

Are there any options to allow link windows .lib with gcc/g++ under mingw64?

Thanks

This related "Linking *.lib files with MinGW" question doesn't mention "File format not recognize" error. See also my comments below.

bcag2

Community
  • 1
  • 1
bcag2
  • 1,988
  • 1
  • 17
  • 31
  • Possible duplicate of [Linking \*.lib files with MinGW](http://stackoverflow.com/questions/7241047/linking-lib-files-with-mingw) Oh, and if it is an really old .lib made for\by Borland compiler from 90s, it might be not compatible with anything but their compiler – Swift - Friday Pie Jan 03 '17 at 16:14
  • I tried to rename the lib file without success… in fact g++ read the file but can't works with. – bcag2 Jan 04 '17 at 07:58
  • I tried too Lib2a wich return "invalid or corrupt import library". The last version of PComm Lite from Moxa was released in 2012-05 so I don't think it was with Borland. It is my program that was initialy wrote with Borland but it is not the issue! – bcag2 Jan 04 '17 at 09:42
  • if that windows app, why you port it to Linux API? And no, you can't use window library files for mingw, because migw emulates gcc in Linux environment, it uses GNU C++ format of binaries. You either should use Linux library, OSS or from Moxa. I would be surprised if Moxa didn't do that). Accepted answer to THAT question is your answer – Swift - Friday Pie Jan 05 '17 at 01:27
  • @Swift: No, *mingw* does not emulate the Linux environment. *cygwin* does, but `mingw` is just the GNU Compiler Collection (gcc) running on windows, compiling windows programs and generating windows file formats. The only thing that's different is the format of the debug metadata, the object file format follows Microsoft's standard (COFF, not ELF). – Ben Voigt Jan 06 '17 at 06:28
  • @Swift: I want switch to Linux because I prefer free soft than privative (so my PC run GNU/Linux and because I think to implement lamp server to push datas in data base instead of csv files. I actually make tests with [http://www.teuniz.net/RS-232/] and avoid sio_ moxa functions – bcag2 Jan 06 '17 at 09:43
  • My tests with http://www.teuniz.net/RS-232/ are OK on win7+mingw64 and on GNU/Linux too. On linux, Moxa port are viewed as ttyA11, ttyA12… after run mxinstall so I change rs232.c comports – bcag2 Jan 06 '17 at 15:48

1 Answers1

0

I downloaded last PCommLite for win7 x64.

Copy C:\Program Files\Moxa\PCommLite 1.6\Include\PCOMM.H in my include project folder (lib in my case), and do the same for files PCOMM.dll and PCOMM.lib in C:\Program Files\Moxa\PCommLite 1.6\Lib\x64.

Then I compile with:

g++ -c -std=c++14 -D_hypot=hypot -DWIN32 src/*.cpp -I./lib/

Where -I./lib give access to PCOMM.H and link with:

g++ -shared *.o lib/PCOMM.LIB /c/Windows/System32/msvcr120.dll /c/ProgramData/Anaconda3/python36.dll -o _project.pyd

Of course you can do all in one time and create an .exe:

g++ -o project.exe -Wall -std=c++14 -DWIN32 src/*.cpp -Ilib/ lib/PCOMM.LIB -L./lib/

NO -ansi required as suggested by Moxa support!

Anh Pham
  • 2,108
  • 9
  • 18
  • 29
bcag2
  • 1,988
  • 1
  • 17
  • 31