Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Linking check.c file with an application

  • 1.  Linking check.c file with an application

    Posted 11/26/12 01:36 AM

    Originally posted by: SystemAdmin


    I am using CPLEX12.4 callable library under Windows XP, and I need to use CPXcheckcopylp. I would like to link the file check.c with my application to enable the latter function? My application is written in C language, under MS Visual Studio 2008.
    Any help will be very much appreciated.

    Amar
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Linking check.c file with an application

    Posted 11/26/12 02:39 AM

    Originally posted by: SystemAdmin


    There are two things you need to do:
    1. In the files that use CPXcheckcopylp() include the ilcplex/cplexcheck.h header file.
    2. Add the cplex/examples/src/c/check.c file to the source files of your project.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Linking check.c file with an application

    Posted 11/26/12 04:34 AM

    Originally posted by: SystemAdmin


    Thank you Daniel. This is the way it was done but I am still getting the following error message:
    1>Linking...
    1>Build_lp.obj : error LNK2001: unresolved external symbol "int __stdcall CPXcheckcopylp(struct cpxenv const *,struct cpxlp const *,int,int,int,double const *,double const *,char const *,int const *,int const *,int const *,double const *,double const *,double const *,double const *)" (?CPXcheckcopylp@@YGHPBUcpxenv@@PBUcpxlp@@HHHPBN2PBDPBH442222@Z)
    

    The only instruction added to the file Build_lp is this:
    #include <ilcplex/cplexcheck.h>
    


    Is there any other reason for such an error?

    Best regards,

    Amar
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Linking check.c file with an application

    Posted 11/26/12 04:59 AM

    Originally posted by: T_O


    As a quick and dirty fix, you could try to copy check.c to the beginning of your file and not compile it itself.

    Of course, there should be better solutions, but I am not a Visual Studio expert.

    Best regards,
    Thomas
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Linking check.c file with an application

    Posted 11/26/12 06:31 AM

    Originally posted by: SystemAdmin


    This looks like a C++ mangled function name.
    Is it possible that the source file that uses CPXcheckcopylp() has extension '.cpp' and not '.c'?
    In that case the compiler will think it is compiling a C++ source code and will assume that the functions defined in cplexcheck.h have C++ linkage.
    To work around this problem try including cplexcheck.h like this:
    #ifdef __cplusplus
    extern "C" {
    #endif
    #include <ilcplex/cplexcheck.h>
    #ifdef __cplusplus
    }
    #endif
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Linking check.c file with an application

    Posted 11/27/12 05:13 AM

    Originally posted by: SystemAdmin


    Thank you very much guys. After I included cplexcheck.h the way Daniel suggested, everything is now working fine.
    Thank you again.

    Amar
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Linking check.c file with an application

    Posted 09/23/14 11:51 PM

    Originally posted by: maiklb2005


    I have a similar question. I have a filename.cpp code written in C++ and I would like to invoke a callable library written in C (file admipex1.c). I tried adding cplex/examples/src/c/admipex1.c to the source files, but I get two following errors:

    admipex1.obj : error LNK2005: _main already defined in filename.obj

    fatal error LNK1169: one or more multiply defined symbols found

    Is there a way that a C code can be called from within a C++ code, and/or treated as an external function? Thank you. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Linking check.c file with an application

    Posted 09/24/14 11:35 AM

    Yes, of course you can call C code from C++. But this question should probably be asked on a C/C++ Forum since it has nothing to do with CPLEX.

    In your specific case, the error message says loud and clear what is wrong: your project has two functions called main(). Just remove or rename one of them (I guess you want to change the one in admipex1.c).


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Linking check.c file with an application

    Posted 09/24/14 02:57 PM

    Originally posted by: T_O


    Let me add, that I have been using

    #include <ilcplex/cplexx.h>

    in my C++ codes very often. This works without any problems.

    Some C-Includes have to be wrapped into extern "C" { ... }, but cplexx.h already does this for you.

    Best regards,
    Thomas


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Linking check.c file with an application

    Posted 09/24/14 05:06 PM

    Originally posted by: maiklb2005


    Daniel and Thomas, thank you! However, I resolved the issue a little differently. By using _spawnl(), I executed the admipex1.exe file within the C++ code. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Linking check.c file with an application

    Posted 09/25/14 05:33 AM

    Originally posted by: prasenjit mandal


    Hi Mikhail,

    Can you please inform me how would you able to extract and save CPLEX-generated cuts.

    I am using C++ to writing codes and using Visual Studio platform. 

    I tried to follow the the following link : http://www-01.ibm.com/support/docview.wss?uid=swg21400065

    But, this script need to be run from command prompt. 

    But when I tried to run any Cplex-C concert program from command prompt, it showing me the error: "C1083: Cannot open include file 'ilcplex/cplex.h: so such fine and directory'".

    I used the the command "cl main.c". Further, I also tried to execute the command: "command "cl main.c cplex1251.lib"".
    However, I checked the 'PATH' environmental variable setting. The path "C:\Program Files\IBM\ILOG\CPLEX_Studio1251\cplex\bin\x86_win32;" is already included to the PATH' environmental variable setting. Also, I tried copy the cplex1251.dll to my current directory. But, the program is showing the same error.

    But, when I tried to execute a CPLEX-C++ program from command prompt using command: "cl /EHsc main.cpp", it is working fine.

     

    Therefore, I am getting stuck. Can you please help me. How did you do it, can you please tell it to me elaborately. I am new to coding, so I shall be highly obliged.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Linking check.c file with an application

    Posted 09/25/14 06:07 AM

    Originally posted by: T_O


    I am not a visual studio expert, but the error indicates that you have to specify the correct include path.


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Linking check.c file with an application

    Posted 09/25/14 09:39 PM

    Originally posted by: maiklb2005


    Hi Prasenjit,

    I learned about extracting CPLEX-generated cuts not that long ago, and this can be done only by using C API. I am very far from being an expert in C++ or C, so I cannot comment on errors. I was only able to configure Visual C++ and CPLEX 12.5.1. I followed explanations in: http://www2.udec.cl/~eliseomelgarejo/. It is in Spanish, but easy to follow. Once you configure, you should be able to run C codes as well.

    The example that extracts cuts is supplied by CPLEX and its name is admipex1.c. You will have no trouble finding it. Once you compile and obtain admipex1.exe, you can run it using either command prompt, or using _spawnl() from withing your main C++ code. 

    Hope this helps,

    Mikhail 


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: Linking check.c file with an application

    Posted 09/26/14 09:52 AM

    Originally posted by: prasenjit mandal


    Hi Mikhail,

    Thank you very much for your reply. I am also using C++ to call cplex.

     If I am correctly understanding what you are saying that you are using _spawnl() within your main C++ code to invoke admipex1.exe from you C++ program.

    Still I have some requests.

    1 ) But still you have to user the commands either "admipex1  mexample.mps" or "admipex1 -r mexample.mps" from command prompt to get the admipex1.exe. But when I tried to run any Cplex-C concert program from command prompt, it showing me the error: "C1083: Cannot open include file 'ilcplex/cplex.h: so such fine and directory'". Can you please tell me how did you compile admipex1.c from command prompt.

     

    2) If you please share a sample script for whatever the process you have mentioned (obtaining admipex1.exe and using _spawnl() from your main C++ code) earlier, I shall be highly obliged.


    #CPLEXOptimizers
    #DecisionOptimization


  • 15.  Re: Linking check.c file with an application

    Posted 09/30/14 11:03 PM

    Originally posted by: maiklb2005


    Prasenjit,

     

    1) When compiling, I write "admipex1 filename.lp." MPS files store MIP starts, LP files store LP/MIP formulations. In this example, admipex1.exe takes only MIP formulations. Of course, you need to have that LP file in the corresponding directory.

    2) _spawnl(_P_WAIT, "admipex1.exe", "admipex1.exe", "filename.lp", NULL, NULL), where filename.lp is the same that you need in 1).


    #CPLEXOptimizers
    #DecisionOptimization