Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I defined source & header -"MathCore.h" & "MathCore.cpp"
MathCore.h as below code :
C++
#ifdef MATHCORE_EXPORTS
#define MATHCORE_API __declspec(dllexport)
#else
#define MATHCORE_API __declspec(dllimport)
#endif

MATHCORE_API bool isPowOf_Two(unsigned int n);
MATHCORE_API bool isFormOf_tpnmo(unsigned int n);
MATHCORE_API int isolate_LST( int x);


// This class is exported from the MathCore.dll
class MATHCORE_API MathEngine {
public:
	MathEngine(void);
	// TODO: add your methods here.
};

extern MATHCORE_API int nMathCore;

MATHCORE_API int fnMathCore(void);

and I generated lib - "MathCore.lib" and respective dll-"MathCore.dll" from visual studio 2008,then I created C++ source file-"t.cpp" in a different folder which uses functions defined in MathCore,for simplicity I put MathCore.lib and MathCore.dll within same folder.
t.cpp like this....
C++
#pragma comment(lib, "MathCore.lib")
#include <iostream>
#include "MathCore.h"

using namespace std;

MATHCORE_API bool isPowOf_Two(unsigned int n);
MATHCORE_API bool isFormOf_tpnmo(unsigned int n);

int main()
{

    while(1){
    unsigned int x;
    cin>>x;
    cout<<isPowOf_Two(x)<<"\n";
    cout<<x<<"\n";
    }
    system("Pause");
    return 0;
}


My problem is.. without using Visual Studio I want to compile the t.cpp using batch file say -"run.bat"
so I included "vcvarsall.bat" and "vcvars32.bat" to same source folder,my "run.bat" commands like this ....
@echo off
call "vcvarsall.bat"
call "vcvars32.bat"
echo off
cl /O2 t.cpp /link MathCore.lib
@if ERRORLEVEL == 0 (
   goto good
)

@if ERRORLEVEL != 0 (
   goto bad
)

:good
   echo "clean compile"
   echo %ERRORLEVEL%
   goto end

:bad
   echo "error or warning"
   echo %ERRORLEVEL%
   goto end

:end


when I run "run.bat" it creates "t.obj" without "t.exe" I think it does not link MathCore.lib,I want to know how to compile visual C++ source with additional libraries and includes in commandline I chekc visual studio commandline arguements It not helped me to solve this problem.

Please anyone know exact commandline arguements to compile a visual c++ source file with needed libs files.
Posted
Updated 18-Dec-13 22:10pm
v4

I would use
CL /O2 t.cpp MathCore.lib
 
Share this answer
 
Comments
Maciej Los 19-Dec-13 4:10am    
Carlo, do you want to say that /link switch is unnecessary?
CPallini 19-Dec-13 4:26am    
In my opinion it is not appropriate. It should be used to pass an option to the linker.
Maciej Los 19-Dec-13 4:36am    
Sounds reasonable ;)
+5!
CPallini 19-Dec-13 4:43am    
Thank you.
 
Share this answer
 
Comments
Maciej Los 19-Dec-13 4:36am    
Good links!
+5!
Richard MacCutchan 19-Dec-13 4:49am    
Thanks, not difficult to find.
Maciej Los 19-Dec-13 4:51am    
I know ;)
:laugh:
Buddhi Chaturanga 19-Dec-13 8:34am    
when linking X64 target machine type lib with our t.obj it keep saying that "kernel32.lib" is missing ,kernel32.lib consists in WIN SDK("C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64") so I want to know how to give this path when the compilation of t.cpp is running through a bat file
Richard MacCutchan 19-Dec-13 11:06am    
You must include the names of all required library files in your command line, nothing is assumed for you. Quite frankly I think you could make life much easier for yourself by using Visual Studio.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900