2 * MICO --- an Open Source CORBA implementation
3 * Copyright (c) 2003 Harald B�hme
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * For more information, visit the MICO Home Page at
20 * http://www.mico.org/
23 /* Modified by Cedric Gustin <cedric.gustin@gmail.com> on 2006/01/13 :
24 * Redirect the output of dumpbin to dumpbin.out instead of reading the
25 * output stream of popen, as it fails with Visual Studio 2005 in
26 * pre-link build events.
35 int main(int argc,char** argv)
38 cerr << "Usage: " << argv[0] << " <def-file-name> <dll-base-name> <obj-file> ...." << endl;
42 // CG : Explicitly redirect stdout to dumpbin.out.
43 string dumpbin = "dumpbin /SYMBOLS /OUT:dumpbin.out";
53 if( (dump = _popen(dumpbin.c_str(),"r")) == NULL ) {
54 cerr << "could not popen dumpbin" << endl;
58 // CG : Wait for the dumpbin process to finish and open dumpbin.out.
60 dump=fopen("dumpbin.out","r");
62 ofstream def_file(argv[1]);
64 def_file << "LIBRARY " << argv[2] << endl;
65 def_file << "EXPORTS" << endl;
71 if( fgets( buf, 64999, dump ) != NULL ) {
72 if(!strstr(buf," UNDEF ") && strstr(buf," External ")) {
73 char *s = strchr(buf,'|') + 1;
74 while(*s == ' ' || *s == '\t') s++;
76 while(*e != ' ' && *e != '\t' && *e != '\0' && *e!= '\n') e++;
79 if(strchr(s,'?')==0 && s[0]=='_' && strchr(s,'@') == 0 )//this is a C export type: _fct -> fct
80 def_file << " " << (s+1) << endl;
82 if(strchr(s,'?')!=0 && strncmp(s,"??_G",4)!=0 && strncmp(s,"??_E",4)!=0) {
83 def_file << " " << s << endl;
89 // CG : Close dumpbin.out and delete it.
91 remove("dumpbin.out");
93 cout << dumpbin.c_str() << endl;