Compile MT and CLR with static Lib help
Help!,
I need to compile this code with static libs so it run on another XP
machine that does'nt have
MS Studio installed. When I compile now I get an ERROR:
1>------ Rebuild All started: Project: drawing_control, Configuration:
Release Win32 ------
1>Deleting intermediate and output files for project 'drawing_control',
configuration 'Release|Win32'
1>Compiling...
1>cl : Command line error D8016 : '/MT' and '/clr:oldsyntax'
command-line options are incompatible
1>Build log was saved at "file://c:\Documents and
Settings\Grant\Desktop\drawing_control\drawing_control\Release\BuildLog.htm"
1>drawing_control - 1 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
This started happening when I included MT in my code. I am using multi
threading just to hold a loop for 24 hours and then run the program
again. The program compares two data files and generates differences
output files and reports.
I am not a full time programmer and my first time with MS Studio so I
don't really understand all the switches for generating released code.
Anyone have help or ideas on how to get this turn on another XP machine
would be greatly appreciated.
Thanks in advance,
JC
-----------------------------
Below is the full code:
#include "stdafx.h"
#include <fstream>
#include <iostream> // for cout
#include <string>
#include <vector>
#include <time.h>
#include <sstream>
#using <mscorlib.dll>
// -----------DEFINE FILES USED ---------------
#define CONTROL_LIST "C:\\DWG_DATA\\DOCUMENTS_LIST.dat"
#define CONTROL_LIST_TEMP "C:\\DWG_DATA\\DOCUMENTS_LIST_TEMP.dat"
#define REQUEST_LIST_DWG "C:\\DWG_DATA\\REQUEST_LIST_DWG.txt"
#define REQUEST_LIST_PRO "C:\\DWG_DATA\\REQUEST_LIST_PRO.txt"
// -----------DEFINE MACROS USED---------------------
#define get_quoted
data.substr((data.find(0x22,0))+1,(data.rfind(0x22,data.length()))-(data.find(0x22,0)+1))
//---------------------------------------------------
using namespace System;
using namespace System::Threading;
using namespace std;
// -----------DEFINE GLOBAL VARIABLES ---------------
string requester = ""; // i.e. "Doug Jerram"
/ used to identify requester
string phone = ""; // i.e. "XXX-531-7448"
/ full phone number of requester
string department = ""; // i.e. "4035"
/ department of requester
string email_req = ""; // i.e. "dou.jer@bio.com" / email
address of requester
string email_rpt = ""; // i.e. "dou.jer@bio.com" / email
address for reporting, omit to cancel
string delivery = ""; // i.e. "4035"
/ include if you want documents mailed and not held
string print_cover_ip = ""; // i.e. "192.168.10.10"
/ printer for BOLD cover sheets, omit to cancel
string request_archive = ""; // i.e. "c:\\dwg_data\\requests\\"
/ file path to archived document requests
string print_request = ""; // i.e. "HP_XXXXXXXX"
/ printer to print document requests
string email_doc = ""; // i.e. "dan.godbe@bio" /
email address for document control request
string movex_query = ""; // i.e.
"c:\\dwg_data\\documents_movex.dat" / file path to movex report file
string request_log = ""; // i.e. "c:\\dwg_data\\request_log.txt"
/ file path to event output log
//
// Declare your class, and then declare your objects
//--------------------------------------------
static TimeSpan waitTime = TimeSpan(0, 0, 1); //SETS SLEEP
hours,minutes,seconds
__gc class Test
{
public:
static void Work()
{
Thread::Sleep(waitTime);
}
};
//----------------------------------------
struct tm newtime;
__time32_t aclock;
//----- FUNCTIONS DECLARED/DEFINED ----------
void Tokenize2(string const& str, vector<string>& tokens,
string const& delimiters=" ,\t\n") {
// There must be at least one token
string::size_type tok_end = str.find_first_of(delimiters);
tokens.push_back(str.substr(0, tok_end));
// Now search for more tokens, if any
while(string::npos != tok_end) {
// Next token starts one past where the last ended
string::size_type tok_start = tok_end + 1;
// Find the end of the token
tok_end = str.find_first_of(delimiters, tok_start);
string::size_type tok_len = tok_end == string::npos ?
string::npos:tok_end - tok_start;
// Add it to the list
tokens.push_back(str.substr(tok_start, tok_len));
}
}
void Tokenize(const string& str,
vector<string>& tokens,
const string& delimiters = " ,\t\n") //const string& delimiters =
",")
{
string::size_type lastPos = str.find_first_not_of(delimiters, 0); //
Skip delimiters at beginning.
string::size_type pos = str.find_first_of(delimiters, lastPos); //
Find first "non-delimiter".
while (string::npos != pos || string::npos != lastPos)
{
tokens.push_back(str.substr(lastPos, pos - lastPos)); // Found a
token, add it to the vector.
lastPos = str.find_first_not_of(delimiters, pos); // Skip
delimiters. Note the "not_of"
pos = str.find_first_of(delimiters, lastPos); // Find next
"non-delimiter"
}
}
void cleanup(void);
void missing_token(void);
void get_definitions(void);
string get_time(void);
//----- MAIN
------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
string movex_document;
string movex_edition;
string control_document;
string control_edition;
string control_doctype;
string control_coptype;
string control_cell;
string control_descriptor;
string control_color;
string control_copies;
string control_books;
string control_books_str;
string control_list_line;
string movex_query_line;
string time_stamp;
int dwg_created = 0;
int pro_created = 0;
int i=0;
atexit(cleanup);
//--SLEEP THREAD
while (1)
{
Thread* newThread = new Thread(new ThreadStart(0, Test::Work));
newThread->Start();
if(newThread->Join(waitTime + waitTime))
{
//--SLEEP THREAD
time_stamp = get_time();
missing_token(); // Check for missing Document Token in
CONTROL_LIST file
get_definitions(); // Read in definitions from CONTROL_LIST
"C:\\DWG_DATA\\DOCUMENTS_LIST.dat"
ofstream f_pro_request(REQUEST_LIST_PRO);
if (!f_pro_request)
{
cout << "File " << REQUEST_LIST_PRO <<'\n';
perror( "Error opening file" );
// LOG ERROR
return -1;
}
else
{
f_pro_request <<"
";
f_pro_request <<"
"<<endl;
}
ofstream f_dwg_request(REQUEST_LIST_DWG);
if (!f_dwg_request)
{
cout << "File " << REQUEST_LIST_DWG <<'\n';
perror( "Error opening file" );
// LOG ERROR
return -1;
}
else
{
f_dwg_request <<"
";
f_dwg_request <<"
"<<endl;
}
ofstream outf2(CONTROL_LIST_TEMP);
if (!outf2)
{
cout << "File " << CONTROL_LIST_TEMP <<'\n';
perror( "Error opening file" );
return -1;
}
ofstream outl(request_log.c_str(), ios::out | ios::app );
if (!outl)
{
cout << "File " << request_log <<'\n';
perror( "Error opening file" );
return -1;
}
ifstream inf(CONTROL_LIST);
if (!inf)
{
cout << "File " << CONTROL_LIST <<'\n';
perror( "Error opening file" );
return -1;
}
while ((getline(inf,control_list_line)) != NULL)
{
if ( ((control_list_line.substr(0,1)) != ";") &&
((control_list_line.substr(0,6)) != "DEFINE") &&
(! control_list_line.empty()) )
{
vector<string> tokens;
int len = control_list_line.length();
for (int a=0; a<len; ++a)
control_list_line[a]=toupper(control_list_line[a]);
Tokenize2(control_list_line, tokens);
if (tokens.size() >= 8)
{
control_document = tokens[0];
control_edition = tokens[1];
control_doctype = tokens[2]; // added for doc type
if (control_doctype == "PROCEDURE");
else if (control_doctype == "DRAWING");
else
{
outl <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
outl <<"ERROR: Document Type Incorrect: " <<
control_document<<" Rev "<< control_edition<<" -> "<<control_doctype
<<'\n';
cout <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
cout <<"ERROR: Document Type Incorrect: " <<
control_document<<" Rev "<< control_edition<<" -> "<<control_doctype
<<'\n';
exit (1);
}
control_coptype = tokens[3]; // added for copy type
if (control_coptype == "OFFICIAL");
else if (control_coptype != "REFERENCE");
else
{
outl <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
outl <<"ERROR: Copy Type Incorrect: " << control_document<<"
Rev "<< control_edition<<" -> "<<control_coptype <<'\n';
cout <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
cout <<"ERROR: Copy Type Incorrect: " <<
control_document<<" Rev "<< control_edition<<" -> "<<control_coptype
<<'\n';
exit (1);
}
control_cell = tokens[4];
control_descriptor = tokens[5];
control_color = tokens[6];
control_copies = tokens[7];
istringstream conv(tokens[7]);
int x;
conv >> x;
string booktmp = "";
control_books = "";
control_books_str = "";
if (tokens.size()== 8+x)
{
for (int i=x+7;i>=8;i--)
{
booktmp = tokens[i];
control_books = "," + booktmp + control_books;
control_books_str = "*" + booktmp + control_books_str;
}
}
else
{
outl <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
outl <<"ERROR: Bad Document Description in "<< CONTROL_LIST
<<'\n';
outl <<"Check Copies & Book Numbers -> "<< control_list_line
<<'\n';
cout <<"Current date and time: "<<time_stamp<<'\n';
cout <<"ERROR: Bad Document Description in "<< CONTROL_LIST
<<'\n';
cout <<"Check Copies & Book Numbers -> "<< control_list_line
<<'\n';
exit(1);
}
}
else
{
outl <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
outl <<"ERROR: Bad Document Description in "<< CONTROL_LIST
<<'\n';
outl <<"Check Document Definition -> "<< control_list_line
<<'\n';
cout <<"Current date and time: "<<time_stamp<<'\n';
cout <<"ERROR: Bad Document Description in "<< CONTROL_LIST
<<'\n';
cout <<"Check Document Definition -> "<< control_list_line
<<'\n';
exit(1);
}
//----- read movex file
ifstream inf2(movex_query.c_str());
if (!inf2)
{
cout << "File " << movex_query <<'\n';
perror( "Error opening file" );
return -1;
}
while (getline(inf2,movex_query_line) != NULL )
{
if (! movex_query_line.empty())
{
vector<string> tokens;
int len = movex_query_line.length();
for (int a=0; a<len; ++a)
movex_query_line[a]=toupper(movex_query_line[a]);
Tokenize(movex_query_line, tokens);
movex_document = tokens[0];
if (movex_document.empty())
{
movex_document = "MISSING";
outl <<'\n'<<"Current date and time:
"<<time_stamp<<'\n';
outl <<"ERROR: MOVEX - MISSING DOCUMENT FIELD"<<'\n';
cout <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
cout <<"ERROR: MOVEX - MISSING DOCUMENT FIELD"<<'\n';
}
if (tokens.size()>1) movex_edition = tokens[1];
else
{
movex_edition = "MISSING";
outl <<'\n'<<"Current date and time:
"<<time_stamp<<'\n';
outl <<"ERROR: MOVEX - MISSING EDITION FOR ->
"<<movex_document<<'\n';
cout <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
cout <<"ERROR: MOVEX - MISSING EDITION FOR ->
"<<movex_document<<'\n';
// GENERATE AND EMAIL REPORT
}
}
if((control_document == movex_document) && (control_edition !=
movex_edition))
{
if(control_edition > movex_edition) //CHECK
aphabetical order
{
cout<<"ERROR: MOVEX DOCUMENT
"<<movex_document<<" REV "<<movex_edition<<'\n';
cout<<"ERROR: EDITION IS OUT OF DATE!"<<'\n';
cout<<"ERROR: EDITION SHOULD BE
-"<<control_edition<<"- OR HIGHER"<<'\n';
movex_edition = control_edition;
// GENERATE AND EMAIL WARNING REPORT
}
outl <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
outl << "WARNING!!! Document " << control_document <<" Edition
"<< control_edition<<" Has been changed!"<<'\n';
outl << "WARNING!!! Revision has changed to ["<< movex_edition
<<"] Replace old documents!"<<'\n';
cout <<'\n'<<"Current date and time: "<<time_stamp<<'\n';
cout << "WARNING!!! Document " << control_document <<" Edition
"<< control_edition<<" Has been changed!"<<'\n';
cout << "WARNING!!! Revision has changed to ["<< movex_edition
<<"] Replace old documents!"<<'\n';
if (control_doctype == "PROCEDURE")
{
pro_created = 1;
f_pro_request << movex_document<<","<<
movex_edition<<","<<control_doctype<<","<<control_copies<<","<<control_coptype<<","<<control_cell<<"-"<<control_descriptor<<"-"<<control_color<<control_books_str<<
endl; // output to request list for Procedures
}
else if (control_doctype == "DRAWING")
{
dwg_created = 1;
f_dwg_request << movex_document<<","<<
movex_edition<<","<<control_doctype<<","<<control_copies<<","<<control_coptype<<","<<control_cell<<"-"<<control_descriptor<<"-"<<control_color<<control_books_str<<
endl; // output to request list for Drawings
}
control_edition = movex_edition;
}
}
inf2.close();
outf2 << control_document<<","<<
control_edition<<","<<control_doctype<<","<<control_coptype<<","<<control_cell<<","<<control_descriptor<<","<<control_color<<","<<control_copies<<control_books<<
endl;
}
else
{
outf2 <<control_list_line<<endl;
}
}
if ((f_dwg_request) && (dwg_created == 1))
{
f_dwg_request.seekp (0,ios_base::beg);
f_dwg_request <<"Document,Edition,Copies,Release,Notes"<<endl;
f_dwg_request <<requester<<","<<phone<<","<<time_stamp<<",Please
return copies through interoffice mail,"<<delivery; // place requester
info here
f_dwg_request.close();
}
else
{
f_dwg_request.close();
remove(REQUEST_LIST_DWG);
}
if ((f_pro_request) && (pro_created == 1))
{
f_pro_request.seekp (0,ios_base::beg);
f_pro_request <<"Document,Edition,Copies,Release,Notes"<<endl;
f_pro_request <<requester<<","<<phone<<","<<time_stamp<<",Please
return copies through interoffice mail,"<<delivery; // place requester
info here
f_pro_request.close();
}
else
{
f_pro_request.close();
remove(REQUEST_LIST_PRO);
}
///* ////////////////////////////////////////////remove after test
if( remove(CONTROL_LIST) == -1 )
perror( "Error deleting file" );
else
{
int result;
result= rename(CONTROL_LIST_TEMP,CONTROL_LIST);
if (result != 0 )
perror( "Error renaming file" );
}
//*/ /////////////////////////////////////////////remove after test
cleanup();
cout <<'\n'<<"PROCESSING COMPLETE "<<get_time()<<'\n';;
//--SLEEP THREAD
}
else
{
Console::WriteLine(S"Join timed out.");
}
exit(1); ///////////////////////////////// ADDED TO STOP TIME
LOOP
}
//-------SLEEP THREAD
return 0;
}
//-------------- END OF MAIN ------------------------
/* TEMPORARY CODE SNIPETS
"next 3 lines copies file to lpt1 printer"
std::ifstream input("abc.prn", std::ios::in | std::ios::binary);
std::ofstream output("lpt1", std::ios::out | std::ios::binary);
output << input.rdbuf();
snippet on how to copy a file
string command("copy ");
system((command + oldname + " " + newname).c_str());
snippet on hot to delete a file
remove(CONTROL_LIST_TEMP);
*/
//--------- FUNCTION DEFINITIONS ---------------------
void cleanup()
{
_fcloseall();
remove(CONTROL_LIST_TEMP);
}
//-----------------------------
string get_time(void)
{
char buffer[32];
errno_t errNum;
_time32( &aclock ); // Get time in seconds.
_localtime32_s( &newtime, &aclock ); // Convert time to struct tm
form.
errNum = asctime_s(buffer, 32, &newtime);
if (errNum)
{
printf("Error code: %d", (int)errNum); // Print local time as a
string.
exit(1);
}
string time_stamp((char*)buffer, 24);
return time_stamp;
}
//-------------------------------------
void missing_token(void)
{
string data;
ifstream dat(CONTROL_LIST);
if (!dat)
{
cout << "File " << CONTROL_LIST <<'\n';
perror( "Error opening file" );
exit(1);
}
while ((getline(dat,data))!= NULL)
{
if ((! data.empty()) && ((data.substr(0,1)) == ","))
{
cout <<"ERROR: Bad Document Description in "<< CONTROL_LIST <<'\n';
cout <<"Check Document Definition -> "<<data<<'\n';
dat.close();
exit(1);
}
}
dat.close();
}
//--------------------------------------
void get_definitions(void)
{
string data;
ifstream dat(CONTROL_LIST);
if (!dat)
{
cout << "File " << CONTROL_LIST <<'\n';
perror( "Error opening file" );
exit(1);
}
while ((getline(dat,data))!= NULL)
{
if (! data.empty())
{
vector<string> definition;
Tokenize(data, definition);
if(definition[0] == "DEFINE")
{
if(definition.size() > 2) // NEED TO CHECK IF ALL
ARE ASIGNED GOOD VALUES
{
if(definition[1] == "requester")
requester = get_quoted;
else if(definition[1] == "phone")
phone = get_quoted;
else if(definition[1] == "department")
department = get_quoted;
else if(definition[1] == "email_req")
email_req = get_quoted;
else if(definition[1] == "email_rpt")
email_rpt = get_quoted;
else if(definition[1] == "delivery")
delivery = get_quoted;
else if(definition[1] == "print_cover")
print_cover_ip = get_quoted;
else if(definition[1] == "request_archive")
request_archive = get_quoted;
else if(definition[1] == "print_request")
print_request = get_quoted;
else if(definition[1] == "email_doc")
email_doc = get_quoted;
else if(definition[1] == "movex_query")
movex_query = get_quoted;
else if(definition[1] == "request_log")
request_log = get_quoted;
}
}
}
}
dat.close();
}
//------------------