using lp_solve with visual studio 2015 - c++

I'm rather new to C++. I'm trying to use VS2015 and the lp_solve library(https://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.5/) to solve my linear eq problem(for exact Gromov-Hausdorrf Distance, see https://mediatum.ub.tum.de/doc/1231885/1231885.pdf section 3.1 and 3.3). My machine is x64 system. Here is what I've done:
donwload the lp_solve_5.5.2.5_dev_win64.zip package and decompress it.
specific the library directoy(through project -> properties -> linker)
specific lib I used (liblpsolve55.lib and liblpsolve55d.lib for statically linking) through project->properties->linker->input->additional dependency.
declare the .h file directory(through project->properties->C/C++).
Here is what I declare in my code:
#include "lp_lib.h"
#pragma comment(lib, "liblpsolve55.lib") // static
#pragma comment(lib, "liblpsolve55d.lib") // static for debug
While when I run the code with x86, it will show the following problems:
error LNK2019: unresolved external symbol _make_lp#8 referenced in function "void __cdecl my_solve [totally 13 errors like this]
warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64' [totally 2 warnings like this]
While when I switch the runner with x64:
I got 550 errors, mainly due to the “dlfcn.h”: No such file or directory
in the lp_lib.h file, it has lines:
#if (LoadInverseLib == TRUE) || (LoadLanguageLib == TRUE)
#ifdef WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#endif
which means it has treat me as a linux machine since dlfcn.h is for unix/linux
I've also try to use the 32bit version package(lp_solve_5.5.2.5_dev_win32.zip), but it do not work either.
with x86 runner:__iob, _printf issues.
with x64 runner:“dlfcn.h”: No such file or directory
I've successively build and run the demo in my mac with the corresponding package(lp_solve_5.5.2.5_dev_osx32.tar.gz). But I still want to know how to build and run it in VS2015.
Here I'll state what I do in mac if anyone need it(using Xcode).
download the lp_solve_5.5.2.5_dev_osx32.tar.gz package
add all the .h file in build phase -> headers
add the liblpsolve55.a file in build phase -> link binary with libraries
(if you want to use .dylib as dynamic linking, add it to the build phase -> copy file, but it do not work for me)
in build setting, set the Architectures to 32-bit intel
in build setting, set the Build Active Architecture Only to No
Thank you very much, actually nobody answer this question :) But I've solve the problem myself. Here is what I do for VS2015:
use package lp_solve_5.5.2.5_dev_win32.zip
add the .h file and .lib as above
change the run library, through properties -> C/C++ -> code generation -> run library -> change the DLL(/MDd) to (/MTd)
if you still got some fprintf issues, go to properties -> linker -> input -> additional dependency, and add : legacy_stdio_definitions.lib
That will be OK. That my be some translation issue, yes I use the chinese-version VS...

Related

unresolved external symbol error even when setup of visual studio project is done properly

In a nutshell
I am tring to use an existing C++ library.
The problem is that it's not compiled.
I took the src code (a visual studio project) and tried to compile it.
The thing is that I can't link my project to the library.
More specific details are:
What I have already done is the following:
I opened the .sln file and added another sub-project called "Sampler"
I downloaded all Microsoft additional packages that the library src code depends on.
I compiled the library to Windows 32 platform x86 (using Visual Studio 2022). The compilation was successful.
I created a directory Dependencies\OPCClientToolKit in same directory of .sln file, Dependencies\OPCClientToolKit contains two directories include and lib.
I put in Dependencies\OPCClientToolKit\lib the .lib - the output after compilation.
I put in Dependencies\OPCClientToolKit\include the .h files of the src code of sdk library.
I added a dependency .h files via Sampler Project > Properies > C++ General. See pictures below.
I added a dependency folder Dependencies\OPCClientToolKit\lib via Sampler Project > Properies > Linker General. See pictures below.
I added a dependency OPCClientToolKit.lib via Sampler Project > Properies > Linker Input. See pictures below.
As far as I know all my step seems valid and fine.
But when, I am compiling (hitting Build via Visual Studio) the Sampler project code (see the code below) I am getting an error message:
Error Message:
1>------ Build started: Project: Sampler, Configuration: Release Win32 ------
1>Sampler.cpp
1>Sampler.obj : error LNK2001: unresolved external symbol "public: static class COPCHost * __cdecl COPCClient::makeHost(class ATL::CStringT<wchar_t,class ATL::StrTraitATL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?makeHost#COPCClient##SAPAVCOPCHost##ABV?$CStringT#_WV?$StrTraitATL#_WV?$ChTraitsCRT#_W#ATL###ATL###ATL###Z)
1>C:\Users\Mark\Desktop\Projects\PID\OPC_DA\Release\Sampler.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Sampler.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please explain to me how should I resolve this issue. I just want to include and use this library and not to modify it.
Dependecies\OPCClientToolKit\lib
Dependecies\OPCClientToolKit\include
Sampler Project > Properties > C++ > General
Sampler Project > Properties > Linker > General
Sampler Project > Properties > Linker > Input
I am using this library (OPC client sdk):
https://sourceforge.net/projects/opcclient/
A usage example made by other guy on the internet:
https://github.com/Tibalt/OPC_DA/blob/master/OPCClientDemo/OPCClientDemo.cpp
My code just use functions and objects of that library.
In details, just trying to initialize opc connection to a server on localhost:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <sys\timeb.h>
#include "opcda.h"
#include "OPCClient.h"
#include "OPCHost.h"
#include "OPCServer.h"
#include "OPCGroup.h"
#include "OPCItem.h"
using namespace std;
int main(void) {
COPCClient::init();
cout << "Done Init";
cout << endl;
CString hostName = "localhost";
COPCHost* host = COPCClient::makeHost(hostName);
}
That project OPCClientToolKit is very old. It looks like built with using ANSI character set, without using the macro _UNICODE. You should either
Remove the macro _UNICODE from the preprocessor settings in your project.
Or add that entire project OPCClientToolKit as a dependency to your visual studio solution and add the macro _UNICODE to that project.
Or use the solution of that project OPCClientToolKit and rebuild the static library OPCClientToolKit.lib with the macro _UNICODE.

trouble with setting up OpenCV 4.1.1 on Visual "Microsoft studio 2019" ? (Illegal Instruction.)

I am trying to use Open Cv on Visual studio to write c++ code. I tried a lot of ways to reach this goal for 3 days. here is what I did in these days:
**1.download and extract open cv 4.1.1 (C:\opencv).
2.download and install Visual Microsoft Studio 2019.
3.copy the bin directory of open cv to the system variable path.
(in my case:"C:\opencv\build\x64\vc15\bin;C:\opencv\build" )
4.add include folder to the project's properties(my project name is opencv):
(properties->configuration properties ->edite include directories value to : (C:\opencv\build\include )
5.edite library directory to ( C:\opencv\build\x64\vc15\lib)
6.then in linker menu->inpute->adittional dependancies -> edit its value to "opencv_world411d.lib" .**
now I write a simple code to test open cv:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat im = imread("cameraman.tiff", 0);
}
this code built correctly but when I run it It doesn't work with error :
Unhandled exception at 0x000007FEBA8D3AE2 (opencv_world411d.dll) in opencv.exe: 0xC000001D: Illegal Instruction.
gfluidimgproc_func.simd.hpp not found
You need to find gfluidimgproc_func.simd.hpp to view the source for the current call stack frame
"I added screenshot"
error report
also, I tried Cmake too.
first, configure and generate OpenCV's source file.
second, open the project in Microsoft visual studio and build all
then I build the install folder.all has been done successfully.
questions:
1.how can I fix this error to run OpenCV on Microsoft visual studio 2019 ?
does Microsoft visual studio 2019 support open cv 4.1.1? have you tried it?
tanks for your attention.
my operation system is: windows 7
intel core i5
>>4.add include folder to the project's properties(my project name is opencv): (properties->configuration properties ->edite include directories value to : (C:\opencv\build\x64 )
This is wrong, you should add C:\opencv\build\include and C:\opencv\build\include\opencv2 to the include directories in your case.
I test your case on My PC, I use VS2019 and OpenCV4.1.1 to make a test. Your other steps are correct. This step will cause the header file not to be found, so the corresponding function can not be identified and will be displayed as illegal instructions.
I have the same problem and from what I understand it is because we compile in x64 bit and execute it on an old CPU which doesn't support sse3 instructions (in my case an old i5 750). I believe your only solution is to recompile OpenCV either in 32bit or in 64bit with sse3 disabled.

Keep on getting LNK2019 error when mixing C and C++

I'm trying to call C code from C++. I have 3 files: pubsub.cpp, pubsublib.c & pubsublib.h.
I know I have to use extern "C" in order to call a C function from C++.
I've literally tried everything, but I am still getting the following LNK2019 unresolved external symbol error:
LNK2019 unresolved external symbol _thisIsATestFunction referenced in
function _main
pubsublib.c
#include "pubsublib.h"
void thisIsATestFunction()
{
// do something
}
pubsublib.h
#ifndef pubsublib_H
#define pubsublib_H
void thisIsATestFunction();
#endif
pubsub.cpp
#include <string>
#include <iostream>
#ifdef __cplusplus
extern "C"{
#endif
#include "pubsublib.h"
#ifdef __cplusplus
}
#endif
using namespace std;
int main() {
thisIsATestFunction();
return 0;
}
I have also tried to just include the functions but I'm getting the same error. I'm really lost at the moment and have searched a lot... Any help would be greatly appreciated.
It works perfectly fine when you actually link with the necessary file.
When you compile pubsub.cpp you have to add pubsublib.obj to the command line. For example, this solved the problem for me using Visual Studio 2015:
cl -c pubsublib.c
cl pubsub.cpp pubsublib.obj
If you're building with the IDE, you simply need to make sure that pubsublib.c is a dependency and pubsublib.obj is specified as input to the link step.
You have to add a reference to the library in your application.
If you have both projects in one solution in Visual C++ 2015 you
right click your application project
select "Add..." from the drop down menu
select "Reference" from the menu
check you library in the list
If you have each project in its own solution you
right click you application project
select "Properties"
open "Linker" section "Input" page
add your .lib file to the "additional dependencies"
Your application should compile without LNK2019 after doing so.
There are also "build dependencies" to manage, but these do not affect the libraries linked to your project (only the build order).
(I am using a german edition of Visual Studio so please fix the translations if some of them are wrong)
Your declaration works fine, as proves the error message (_thisIsATestFunction is indeed a C-undecorated name).
Now two possibilities remain
the file pubsublib.c was not compiled as C, causing the compiled function to get decorated;
the file pubsublib.c was compiled as C, but didn't take part to the linking.
Only your solution/project(s) file can tell the truth. Can we see a screen copy of the Solution Explorer ?
This linkage error is produced when "pubsublib.c" file is compiled as C++ file (in g++). Please change your project options so that all .cpp files are compiled with g++, and all .c files are compiled with gcc.
After changing settings make sure that "pubsublib.c" file is really compiled with gcc. It can be found in compilation output like following:
g++.exe -c main.cpp -o main.o
gcc.exe -c pubsublib.c -o pubsublib.o
g++.exe main.o pubsublib.o -o Project1.exe

CGAL unresolved externals when compiling/linking on Windows

I'm getting strange (for me) errors during compiling a test program which uses some parts of the CGAL library.
First, the environment:
Windows 7 64 bits
Boost 1.53
CGAL 4.3
Qt 4.8.4
CMake 2.8.10.2
Visual Studio 2010 professional
I installed all the libraries for 32 bits (if this was an option during installation).
Installation wrong?
In order to install CGAL on my computer, I followed this tutorial: http://www.cgal.org/windows_installation.html. I have to note here that this did not work out-of-the-box for me. During the configuration phase of CGAL in CMake, the boost libraries were not found (although I set the corresponding environment variables, as stated in the tutorial). After setting the incorrect variables in CMake, I was able to complete the configuration and generation phase. After that, I was able to compile both the Debug as well as the Release configurations of CGAL in Visual Studio.
In order to test whether the CGAL lib was installed successfully, I tried to compile and run both the examples and demos. These also did not work immediately. The problem was that the CGAL and Boost headers (and binaries) were not found. After setting the right paths in Project properties => Configuration properties => C/C++ => Additional Include Directories and in Project properties => Configuration properties => Linker => Additional Library Directories the examples and demos could be build. I successfully ran these examples after that.
Actual problem
Now, I'm tyring to compile a simple program, in order to be able to make a certain exercise (http://acg.cs.tau.ac.il/courses/algorithmic-robotics/spring-2013/exercises/assignment-2 exercise 2.1). Here, there are two files supplied: basic_typdef.h and cgal_bootcamp.cpp
*basic_typedef.h*
#pragma once
#include <CGAL/Cartesian.h>
#include <CGAL/Gmpq.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Polygon_set_2.h>
#include <list>
/*******************************************************************************************
* This file contatins basic typedefs (from CGAL and more).
*******************************************************************************************/
typedef CGAL::Gmpq Number_type;
typedef CGAL::Cartesian<Number_type> Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon_with_holes;
typedef CGAL::Polygon_set_2<Kernel> Polygon_set;
typedef std::list<Polygon_with_holes> Polygon_with_holes_container;
*cgal_bootcamp.cpp*
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
return 0;
}
(For convenience I removed the comments in the file cgal_bootcamp.cpp)
With Visual Studio, I can compile the two files as above. However, when I try to create a Point (as defined in basic_typedef.h), I'm getting the (strange) errors:
#include "basic_typedef.h"
int main(int argc, char* argv[])
{
/*
1. Point
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Kernel_23_ref/Class_Point_2.html
*/
// Create Point with the coordinates (0.5, 0.6)
Point p;
return 0;
}
The errors that occur:
Error 1 error LNK2019: unresolved external symbol __imp____gmpq_init referenced in function "public: __thiscall CGAL::Gmpq_rep::Gmpq_rep(void)" (??0Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 2 error LNK2019: unresolved external symbol __imp____gmpq_clear referenced in function "public: __thiscall CGAL::Gmpq_rep::~Gmpq_rep(void)" (??1Gmpq_rep#CGAL##QAE#XZ) C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\cgal_bootcamp.obj warmup-exercise
Error 3 error LNK1120: 2 unresolved externals C:\Dropbox\Capita Selecta\Assignments\Assignment 2.1\warmup-exercise\Debug\warmup-exercise.exe 1 1 warmup-exercise
4 IntelliSense: #error directive: "Mixing a dll CGAL library with a static runtime is a really bad idea..." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 364 4
5 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\dev\cgal-4.3\include\cgal\auto_link\auto_link.h 397 4
I have no clue what is going wrong here (I have to note that I'm still a noob with C++). It seems that there is something wrong with the GMP library (at least the linking to this?) I found in another post that for someone there were no libgmp files build (can't find that post anymore), but that is not the case for me (I think): in CGAL-4.3/auxiliary/gmp/lib I see four files, libgmp-10.dll libgmp-10.lib libmpfr-4.dll and libmpfr-4.lib.
Also the error on line 4 points to something that might cause this error ("Mixing a dll CGAL library with a static runtime is a really bad idea..."), but I do not know what this actually means (or how I can resolve it).
Further, I tried to setup all the libraries on another computer, but I got the same errors there also.
Could anyone point me in the right direction to solve this problem? If you need more information, please let me know.
This comment answered the question: the script cgal_create_cmake_script can be used to create a CMake file that can be used to generate a correct Visual Studio project using CGAL.

Having trouble embedding Lua for Windows install into C++ program

This is the first question I have found myself not being able to get to the bottom of using my normal googling/stack overflowing/youtubing routine.
I am trying to compile a minimal Lua program inside of a C++ environment just to ensure my environment is ready to development. The Lua language will be later used for User Interface programming for my C++ game.
First some basic information on my environment:
Windows 7 64-bit
Visual studio 2010
Lua for Windows 5.1 (latest build I could download from google code)
Here is the code I am trying to compile:
// UserInt.cpp : Defines the entry point for the console application.
//
#pragma comment(lib,"lua5.1.dll")
#include "stdafx.h"
#ifndef __LUA_INC_H__
#define __LUA_INC_H__
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
int _tmain(int argc, _TCHAR* argv[])
{
lua_State * ls = luaL_newstate();
return 0;
}
#endif // __LUA_INC_H__
Here is the Error I am getting:
1>UserInt.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _wmain
1>c:\users\deank\documents\visual studio 2010\Projects\UserInt\Debug\UserInt.exe : fatal error LNK1120: 1 unresolved externals
Things I have tried:
I have read about lua_open()(and several other functions) no longer being used so I tried the newstate function instead. I get the same error. This was more of a sanity check than anything. I am using 5.1 and not 5.2 so I do not think this really matters.
I have also read this thread Cannot link a minimal Lua program but it does not seem to help me because I am not running the same environment as that OP. I am on a simple windows 7 and visual studio environment.
The top pragma comment line was something I saw in yet another thread. I get the same error with or without it.
I have gone into my visual studio C++ directories area and added the lua include to the includes and the lua lib to the libraries.
So it seems like my program is seeing the .h and seeing the symbol. But for some reason it is not getting the .cpp implementation for the functions. This is why I was hoping including that .dll directly would help fix the problem, but it hasn't.
So, I feel like I have exhausted all of my options solving this on my own. I hope someone is able to help me move forward here. Lua looks like an awesome language to script in and I would like to get my environment squared away for development.
I hope it is just some silly error on my part. I believe I have provided as much information as I can. If you need more specifics I will update with info if I can provide it.
Edit1
Tried the solution in this Can't build lua a project with lua in VS2010, library issue suspected
That did not work either.
You'll need to have the library (.LIB) file and add that to VS. Use Project > Properties and go to Linker > Input and add the full .lib filename to the "Additional Dependencies" line. Note that the .LIB is different from the .DLL.
Personally, I prefer adding the source code to my project, over referencing the dynamic link library. The following procedure will let you do as such.
Download the source code ( http://www.lua.org/ftp/ ), uncompress it.
In Visual Studio, choose File > New > Project and choose Visual C++, Win32, "Win32 Console Application".
In your project in Visual Studio, add all the source code, except luac.c. Also delete the main() function out of the file that VS created for you. This is usually given the name of the project you specified with the .cpp file extension. You could just remove this file all-together from the project.
Build and Run.
This is the Lua console