Author Topic: Howto - Cross Compiling in Linux using MingW32  (Read 250067 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9414
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #105 on: November 21, 2012, 04:21:07 pm »
Done. Patch 003373.
Nice catch... everything generalising platform differences is usually welcome.

@oBFusCATed: A quick inspection reveals it doens't look bad, indeed. Hence I don't recall what the reBreak_or32 regexp was for. If you test the patch, can you ensure we don't break this particular "thingy"? (It seems a Windows only thing).
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 10019
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #106 on: November 21, 2012, 05:09:33 pm »
I'm not sure too, what type of breakpoints this code is used to detect, so some testing should be done here.
I'll apply this on my work C::B and see if there are problems on linux, for windows somebody else should test it.
<debugger plugin maintainer>
(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!]

Offline eddyq

  • Multiple posting newcomer
  • *
  • Posts: 56
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #107 on: December 01, 2012, 09:21:57 pm »
This is off topic but I can't find anyplace to make a "new post". Can someone please tell me how to do a "new post"?

Offline markpotts

  • Single posting newcomer
  • *
  • Posts: 9
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #108 on: December 28, 2013, 10:05:31 pm »
Any advice on doing the reverse, i.e. cross-compiling for Linux under Windows?
Mark

Offline 71532

  • Single posting newcomer
  • *
  • Posts: 6
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #109 on: August 09, 2014, 12:35:47 am »
The following is just a very simple program writen in C++ that connects to a MySQL. I compile it with no errors, with the following line
g++ -o main main.cpp  -L/usr/include/mysql -lmysqlclient  -I/usr/include/mysql
that produces an executable that runs perfectly well.
/************************************
the example
*************************************/
#include<iostream>
#include<winsock.h>
#include<mysql.h>
#include<stdio.h>
using namespace std;
#define SERVER    "anilab"
#define USER      "anibal"
#define PASSWORD  "anigug"
#define DATABASE  "virtualsa"

int main() {
MYSQL *connect;
connect=mysql_init(NULL);
if(!connect) { cout<<"MySQL Initialization failed"; return 1;
}
connect=mysql_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,0,NULL,0);
if(connect) {   cout<<"connection Succeeded\n";
}else{           cout<<"connection failed\n";      }

MYSQL_RES *res_set;
MYSQL_ROW row;
mysql_query( connect, "SELECT id,nombre,apellido FROM users;" );
unsigned int i =0;
res_set = mysql_store_result(connect);
unsigned int numrows = mysql_num_rows(res_set);
cout << endl;
cout <<"\t --------------------------------------------------------------------- \t"<< endl;
while (((row= mysql_fetch_row(res_set)) !=NULL )) {
//cout<<" %s\n",row !=NULL?row : "NULL";
cout <<"\t | \t" << row << "\t | \t"<<  row[i+1] << "\t | \t"<< row[i+2] << "\t | \t" << endl;
cout <<"\t --------------------------------------------------------------------- \t"<< endl;
}
mysql_close (connect);
return 0;
}
/*********** end of file ***********/

Question: does anybody know of a way to compile this, using -for example- C::B, that will produce an executable for Windows ?
I had tried the set-up proposed at the top of this thread.
I get the following messages:(taken from the Build log)

i586-mingw32msvc-g++ -I/usr/include/mysql  -DBIG_JOINS=1  -fno-strict-aliasing   -DUNIV_LINUX -DUNIV_LINUX -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -DSTRICT -DHAVE_W32API_H -D__WXMSW__ -D__WINDOWS__   -I/usr/i586-mingw32msvc/include  -c /home/xxxx/cpp/test1/main.cpp -o /home/xxxx/cpp/test1/main.o

i586-mingw32msvc-g++ -L/usr/i586-mingw32msvc/lib  -o /home/xxxx/cpp/test1/main /home/xxxx/cpp/test1/main.o  -lstdc++ -lgcc -lodbc32 -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lodbc32 -lwsock32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid  "-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient"
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: unrecognized option '-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient'
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
 
This compiler (i586-mingw32msvc-g++ does actually produce a working executable from a simple "hello world" C++ source, so it seems a good compiler). Fact is: don't know how to make it work with MySQL libraries and headers.

Thanks

Offline stahta01

  • Lives here!
  • ****
  • Posts: 5797
    • My Best Post
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #110 on: August 09, 2014, 12:47:00 am »
The following is just a very simple program writen in C++ that connects to a MySQL. I compile it with no errors, with the following line
g++ -o main main.cpp  -L/usr/include/mysql -lmysqlclient  -I/usr/include/mysql

Question: does anybody know of a way to compile this, using -for example- C::B, that will produce an executable for Windows ?
I had tried the set-up proposed at the top of this thread.
I get the following messages:(taken from the Build log)

i586-mingw32msvc-g++ -I/usr/include/mysql  -DBIG_JOINS=1  -fno-strict-aliasing   -DUNIV_LINUX -DUNIV_LINUX -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -DSTRICT -DHAVE_W32API_H -D__WXMSW__ -D__WINDOWS__   -I/usr/i586-mingw32msvc/include  -c /home/xxxx/cpp/test1/main.cpp -o /home/xxxx/cpp/test1/main.o

i586-mingw32msvc-g++ -L/usr/i586-mingw32msvc/lib  -o /home/xxxx/cpp/test1/main /home/xxxx/cpp/test1/main.o  -lstdc++ -lgcc -lodbc32 -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lodbc32 -lwsock32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid  "-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient"
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: unrecognized option '-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient'
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
 
This compiler (i586-mingw32msvc-g++ does actually produce a working executable from a simple "hello world" C++ source, so it seems a good compiler). Fact is: don't know how to make it work with MySQL libraries and headers.

Thanks


Where did you enter "-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient" in Code::Blocks?
Did you enter the double quotes or CB?

I suggest trying the "For your project :" section of this FAQ.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline 71532

  • Single posting newcomer
  • *
  • Posts: 6
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #111 on: August 09, 2014, 01:24:16 am »
Hi ! Thanks for the quick reply.
The string "-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient" (without quotes), was entered at the Linker Settings tab ->Link libraries in C::B (I am running a Linux version of C::B)
I got it issuing a mysql_config --cflags and mysql_config --libs to get the compilation and linking "recommended" switches for the MySQL server installed.
I had seen the link you suggested, I already set up the C::B as advised at the top of this post.
It seems that I need to continue searching to see if someone, somewhere, sometime, had ever cross-compiled a C++ source code to obtain a Windows binary executable format able to run on Windows and connect to a MySQL database running elsewhere. I did it, around 15 years ago, with some stuff I do not have anymore (not even a clue). Now I need to do it but I don't know how...
Thanks
Bye


Offline stahta01

  • Lives here!
  • ****
  • Posts: 5797
    • My Best Post
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #112 on: August 09, 2014, 02:08:32 am »
Hi ! Thanks for the quick reply.
The string "-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient" (without quotes), was entered at the Linker Settings tab ->Link libraries in C::B (I am running a Linux version of C::B)
I got it issuing a mysql_config --cflags and mysql_config --libs to get the compilation and linking "recommended" switches for the MySQL server installed.
I had seen the link you suggested, I already set up the C::B as advised at the top of this post.
It seems that I need to continue searching to see if someone, somewhere, sometime, had ever cross-compiled a C++ source code to obtain a Windows binary executable format able to run on Windows and connect to a MySQL database running elsewhere. I did it, around 15 years ago, with some stuff I do not have anymore (not even a clue). Now I need to do it but I don't know how...
Thanks
Bye

That is the wrong location for most of this "-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient"
The "mysqlclient" should be in the Link libraries.
The rest should be in other places.
This "/usr/lib/mysql" in linker search folder/path.
This "-Wl,-Bsymbolic-functions" in linker extraother settings.
No idea where "-rdynamic" should be; but, a good guess is linker extraother settings.

Edit: Remember to use the correct tick marks around `mysql_config --cflags` and `mysql_config --libs`
My guess of where they belong.
Other linker settings: `mysql_config --libs`
Other compiler settings: `mysql_config --cflags`

Note: I have been told both that CB needs exited and restarted for things in "`" ticks to be reread and that CB does NOT need exited.

Tim S.

« Last Edit: August 09, 2014, 02:20:13 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Testing, compiling CB Trunk against wxWidgets 3.0.2.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline 71532

  • Single posting newcomer
  • *
  • Posts: 6
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #113 on: August 09, 2014, 02:55:06 am »
OK Tim.
I already stated where did I get the compiler and linker options, they are in my reply to your reply.
The switches, or compiler and linker options, were obtained from the command line, hence, no need for back-ticks, though they can be called adding for example $(mysql_config --link) whenever the compiler is called from a single line, from a command line or from a shell script.
Now, I will follow your idea of "simpler" link options, although, if you take a look, I already put -lmysqlclient as a switch in the linker tab, as I showed in my last post. Perhaps, simpler options yield a solution.
Fact is, I can produce an executable for Windows (without calling mysql stuff) and an executable for Linux (with mysql stuff) but fail to produce a running Windows binary with mysql abilities...
I wonder if someone (besides me) had ever did it ... It seems hard to me to think that nobody had ever tried it before... Even the people at Code::Blocks...
Anyway, thanks for your attention.
Regards

Offline stahta01

  • Lives here!
  • ****
  • Posts: 5797
    • My Best Post
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #114 on: August 09, 2014, 03:13:46 am »
Please explain why the build log has double quotes around  the part that is causing the error.

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

Offline 71532

  • Single posting newcomer
  • *
  • Posts: 6
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #115 on: August 09, 2014, 04:15:48 am »
OK Tim. Thanks for your concern.
Why the double quotes ? It is pointed by the linker. So probably I should not use it as a linking option, though the MySQL command line
mysql_config --libs
yields that string. I also tried not to use it, and I got many more errors. I just installed Code::Blocks. Now, if, as it seems to me, nobody here had attempted a cross-compilation of a C++ source code to produce a Windows executable able to connect to MySQL, I do not have the time to investigate nor, perhaps, the knowledge of how this thing was written, what are the messages, why are those switches rejected. Maybe the explanation is available. Maybe, it is not. What does the error means ? Well, maybe this will help the C::B developers to explain more clear where to put the things, or why are they "rejected" when they are placed in the "assumed" right place. As I see the things, if C:B does not solve my problem -and it seems it does not- I need to carry on. As said, no time to investigate, not exactly around C::B, maybe I will turn to the compiler, which is a cross-compiler, that does not find the libraries it has to link. So my problem is no C:B-related, my problem is of some other kind, maybe, I need other switches, because I can compile an ELF Linux binary that runs perfectly well, and a Windows binary that runs perfectly well, but not a Windows binary that connects to MySQL. I see I have a problem at linking stage, but I don't know how to solve it. So I should look somewhere else.
Thanks for your concern.
Bye

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7163
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #116 on: August 09, 2014, 10:06:07 am »
It looks like you try to link the mysql lib from the system (linux-lib) with a mingw-app (cross-compiled for windows).
How should this work ?

Offline 71532

  • Single posting newcomer
  • *
  • Posts: 6
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #117 on: August 09, 2014, 02:30:04 pm »
Won't.
Thus, the only way out will be install a MySQL and a Code::Blocks on a Windows box, and compile there.
I already installed a MySQL.
Any other advice in this regard ?
Thank you !

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7163
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #118 on: August 09, 2014, 03:38:37 pm »
It might be possible to use mysql-libs (and headers) from windows on linux (for cross-compiling) or (better) do a cross-builld of mysql on linux.
But that's far away from the scope of our forum, sorry.

Offline raiz

  • Single posting newcomer
  • *
  • Posts: 1
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #119 on: May 08, 2016, 12:28:06 pm »
thanks for information