How to use the C++ standalone ASIO library - c++

I am trying to use the asio library on Windows 10, here is a simple test code block:
#include <iostream>
#include <asio.hpp>
using std::cout;
int main()
{
std::cout << "hello asio\n";
asio::io_context ioc;
asio::steady_timer tmer(ioc, asio::chrono::seconds(1));
tmer.wait();
cout << "hi asio\n";
ioc.run();
return 0;
}
with Visual Studio 2017. To open a developer command prompt, I use the following command
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools>vsdevcmd
Then, based on the asio doc, I run the command nmake -f Makefile.msc under the asio src folder. But I am getting an error:
Microsoft (R) Program Maintenance Utility Version 14.16.27025.1
Copyright (C) Microsoft Corporation. All rights reserved.
cl -Fetests\latency\tcp_client.exe -Fotests\latency\tcp_client.obj -nologo -EHac -GR -I. -I../include -O2 -MD -I../../boost_1_34_1 -D_WIN32_WINNT=0x0501 -DBOOST_ALL_NO_LIB -DBOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING tests\latency\tcp_client.cpp -link -opt:ref
tcp_client.cpp
../include\asio/detail/config.hpp(26): fatal error C1083: Cannot open include file: 'boost/config.hpp': No such file or directory
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.EXE"' : return code '0x2'
Stop.
It seems the library requires boost/config.hpp. I really trying to avoid to use the boost. Is there a way I could use the asio standalone on windows 10?

To use asio without any boost libraries, you have to define ASIO_STANDALONE at some point. The best would be in your Visual Studio project, or in your code before any include of asio header.

I tried to use vcpkg, but it turns out I only need to download the library and create a cmake file to do the job.
cmake_minimum_required(VERSION 3.12)
project(asio)
add_definitions(-DASIO_STANDALONE -D_WIN32_WINNT=0x0501)
# -DBOOST_DATE_TIME_NO_LIB -DBOOST_REGEX_NO_LIB)
# include_directories(${VCPKG_DIR}//asio_x86-windows//include)
include_directories(./../libs/asio-1.12.2/include)
add_executable(asio s5.cpp)

Following command line seems to work. It would be nice addition to boost.asio standalone documentation.
$ nmake STANDALONE=1 -f Makefile.msc
I took me some time to figure out this since I have never used NMAKE even though I have developed a lot of stuff to Windows with MS compiler. It is very not-so-good tool for MAKE process.
Although the make command just executes tests. No lib is generated. Just include headers...

Related

Compiling FFmpeg with Libass using MSVC

First a bit of background.
I'm trying to compile ffmpeg on windows with the libass extensions/configuration option.
Using the visual studio project libass-msvc I built libass using Visual Studio as a static lib.
I then installed MinGW with MSYS and pkg-config. Following the instructions on the ffmpeg MSVC installation guide I configured the environment to build with the MSVC linker and to build in x64.
When I try to configure libass for compilation using ./configure --enable-libass --toolchain=msvc I get the following error in the log file:
File not found ass/ass.h
pkg-config can not find libass
I have tried the following to fix this.
Create a .pc file for libass and add this to the PKG_CONFIG_PATH environment variable. See file content below. (After doing this pkg-config libass --version prints 0.81, not the right version number but at least something.)
Copy libass .h files into a MinGW/include/ass folder and the .lib file into the MinGW/libs folder.
Add libass include and bin folders to PATH environment variable
Download libass and dependencies source then try to build it using MSYS with MSVC compiler. My aim here was to be able to use "make install" and let MinGW install libass to the correct locations. After hours of trying to fix linker errors, I abandoned this idea as some of the libass dependencies make files only work with the GCC GNU compiler.
Compile libass with GCC GNU using MinGW make/make install then try and install libass using the GNU libs. Again this led to linker errors (I know this was a bad idea but was worth a try).
Tried using extra lib and include build configuration options --extra-cflags="ffmpeg-dir/extra/include" \
--extra-ldflags="ffmped-dir/extra/ffmpeg_build/lib" then adding the libs and .h files into those locations
.pc file
libass.pc:
prefix=/MinGW
includedir=libass-directory/include
libdir=libass-director/x64/bin/
Name: libass
Description: Libass project
Version: 0.13.7
I am now completely stuck and out of ideas if anyone could give any insight or suggestions into what I'm doing wrong that would be fantastic.
Update
I created INCLUDE and LIBDIR environment path variable containing the libass paths. Which now correctly includes libass. However, I now get the following linker error for the function check_ass_library_init.
check_func_headers ass/ass.h ass_library_init
check_ld cc
check_cc
BEGIN ./ffconf.RZMYFWdc/test.c
1 #include
2 #include
3 long check_ass_library_init(void) { return (long)
ass_library_init; }
4 int main(void) { int ret = 0;
5 ret |= ((intptr_t)check_ass_library_init) & 0xFFFF;
6 return ret; }
END ./ffconf.RZMYFWdc/test.c
cl -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -
D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -
D_WIN32_WINNT=0x0502 -nologo -c -Fo./ffconf.RZMYFWdc/test.o
./ffconf.RZMYFWdc/test.c
test.c
./ffconf.RZMYFWdc/test.c(3): warning C4311: 'type cast': pointer truncation
from 'ASS_Library *(__cdecl *)(void)' to 'long'
./compat/windows/mslink -nologo -out:./ffconf.RZMYFWdc/test.exe
./ffconf.RZMYFWdc/test.o psapi.lib advapi32.lib shell32.lib ole32.lib
test.o : error LNK2019: unresolved external symbol ass_library_init
referenced in function check_ass_library_init
./ffconf.RZMYFWdc/test.exe : fatal error LNK1120: 1 unresolved externals
ERROR: libass not found using pkg-config
The libass test project which uses ass_library_init compiles fine using the same lib files, the libs appear to be fine.
From what I see from this line "./compat/windows/mslink -nologo -out:./ffconf.RZMYFWdc/test.exe ./ffconf.RZMYFWdc/test.o psapi.lib advapi32.lib shell32.lib ole32.lib" libass is not being passed to the linker.
I suspect that the configuration file is not creating the link to libass in the make file when compiling with MSVC.
Am I correct or am I going about compiling this in the wrong way?

a fatal error in compiling a c++ program

I am using eclipse kepler for C++, in compiling a simple hello world program I saw this error.
c:\mingw\include\_mingw.h:73:20: fatal error: w32api.h: No such file or directory
while the whole windows is as bellow.
09:15:59 **** Incremental Build of configuration Debug for project project1 ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++\\backward" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include-fixed" "-IC:\\MinGW\\lib\\gcc\\mingw32\\5.3.0\\include\\c++\\mingw32" "-IC:\\MinGW\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\project1.o" "..\\src\\project1.cpp"
In file included from c:\mingw\include\wchar.h:53:0,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\cwchar:44,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\bits\postypes.h:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\5.3.0\include\c++\iostream:39,
from ..\src\project1.cpp:2:
c:\mingw\include\_mingw.h:73:20: fatal error: w32api.h: No such file or directory
compilation terminated.
09:16:01 Build Finished (took 2s.535ms)
what can I do?
my code is this
#include <iostream>
using namespace std;
int main()
{
cout<<"hello world";
}
In my case i've solved like this:
Go to MinGW Installation Manager.
Select "Basic Setup" from installation list and tick the package "mingw32-base-bin".
From the installation tab select "Apply Changes".
the problem is related to the MinGW installer. there is a package that must be installed, but it didn't install it. go to the MinGW installer and add the ming-w32-w32.api and then apply changes from installation menu.

sqlite3 error when compiling with cl.exe from MVS 2013 with OMIT opition

When I try to compile the sqlite3.c and shell.c file to create a library, I write
cl.exe /DSQLITE_OMIT_"one.of.the.option." sqlite3.c shell.c
It returns an error:
sqlite3.c
sqlite3.c(155868) : error C2129: static function 'void sqlite3"name of the option choosen"(Parse *,Expr *,Expr *,Expr *)' declared but not defined
sqlite3.c(13360) : see declaration of 'sqlite3"name of the choosen option"'
shell.c
Generating Code...
For example:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin>cl.exe -Os /DSQLITE_OMIT_ANALYZE sqlite3.c shell.c
sqlite3.c
sqlite3.c(155868) : error C2129: static function 'void sqlite3Attach(Parse *,Expr *,Expr *,Expr *)' declared but not defined
sqlite3.c(13360) : see declaration of 'sqlite3Attach'
shell.c
Generating Code...
This happens for all the OMIT options. How can I fix this?
You are trying to compile amalgamation version of the library (packaged as a single source file) and as stated in documentation :
Important Note: The SQLITE_OMIT_* options do not work with the amalgamation or with pre-packaged C code files. SQLITE_OMIT_* compile-time options only work correctly when SQLite is built from canonical source files.
See "Building The Amalgamation" in how to compile section on how to build amalgamation with custom options:
First construct an appropriate Makefile by either running the configure script at the top of the SQLite source tree, or by making a copy of one of the template Makefiles at the top of the source tree. Then hand edit this Makefile to include the desired compile-time options. Finally run:
make sqlite3.c
Or on Windows with MSVC:
nmake /f Makefile.msc sqlite3.c

Get Error When Compile Source (.C) file Using Microsoft Visual C/C++ compiler via GnuWin32 in Windows 7

I will show you step as below ....
First You Download GNUWIN32.
Then Install on windows 7 and Set Environment Path.
I will make a.C Source file shown as below
#include <stdio.h>
int main()
{
//FileName: a.C
printf("Hello World !!! Its works");
return 0;
}
I will to make Makefile. shown as below
#MakeFile Source Code... FileName: Makefile
OBJS: a
#add path visual c/c++ compiler
PATH=C:/Program Files\ (x86)\Microsoft\ Visual\ Studio\ 9.0/VC
CC: $(PATH)/bin/cl.exe
all: a
a:
$(CC) -c a.C
clean:
rm -rf $(OBJS)
I compile Source code. it get error.
Input: C:\Users\*****\Desktop\Test>make
output:
cc -c a.C
process_begin: CreateProcess(NULL, cc -c a.C, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [a] Error 2
Please Let Me help, How to build this code using visual c++ compiler.
PATH is the wrong name to use for a variable in your Makefile, because it is also the name of the variable that lists the paths to be searched when looking for other programs. Change it to something else.
There's a semantic error in your makefile. You are defining CC as a target, not a variable. Fix it thus:
CC=$(PATH)/bin/cl.exe
The clue is in the error message process_begin: CreateProcess(NULL, cc -c a.C, ...) failed.. You can see that it's trying to execute cc not cl.exe
If you have a look at vcvars32.bat, provided by μSoft to set up your environment for the compiler, you will see that it adds several folders to your %PATH% environment variable.
You can express this %PATH% minging in make if you want to. Something like
export PATH := /cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/IDE:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/BIN:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/Common7/Tools:/cygdrive/c/Program Files/Microsoft Visual Studio 9.0/VC/VCPackages:/cygdrive/c/Program Files/Microsoft SDKs/Windows/v6.0A/bin:${PATH}:/cygdrive/C/PROGRA~1/MICROS~2.0/VC/redist/DEBUG_~1/x86/MICROS~1.DEB
Yes, this is make syntax. It augments any existing %PATH% with a prefix and a suffix (see that ${PATH} right in the middle?).
Note though that this is in a format ready for cygwin make. You may need a few adjustments. Oh, and don't forget that cl.exe needs decent settings for %INCLUDE%, %LIB% and %LIBPATH% too.

LINK1104 cannot open boost static library using visual studio 2008 command prompt

I'm trying to compile a cpp file which uses static boost libraries. I'm using the visual studio 2008 command prompt as I have not set up a VS project file.
The command I'm using is (run from the folder containing my source code):
cl /EHsc /I "C:\Program Files\boost\boost_1_53_0" Client.cpp
The error is:
LINK: fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-s-1_53.lib'
However, the file 'libboost_system-vc90-mt-s-1_53.lib' can be found in "C:\Program Files\boost\boost_1_53_0\stage\lib" so my understanding is that I've installed boost properly and I'm just failing to link to it?
I've tried including it directly using
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" /I "C:\Program Files\boost\boost_1_53_0\stage\lib\" Client.cpp
which gives the same error.
I've also tried linking to it directly using /link as follows:
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" /link "C:\Program Files\boost\boost_1_53_0\stage\lib\libboost_system-vc90-mt-s-1_53.lib" Client.cpp
Which returns a different error:
cl : Command line error D8003 : missing source filename
I seem to be calling the compiler flags wrong? But I can't see where/how.
There is a similar question here,but the solution involves issues with how visual studio/ the project file is set up. Since I don't have a project file, is there an easy solution for the above that I can't see or would I need to set up a project?
Thanks for any help in advance!
The linker needs to be told where the library file is located. You were very close with the last command line, but the file name needs to precede the /link option. This should work:
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" Client.cpp /link "C:\Program Files\boost\boost_1_53_0\stage\lib\libboost_system-vc90-mt-s-1_53.lib"
Also, when linking to multiple libraries in the same directory, it is more concise to use the LIBPATH option to tell the linker where to look for .lib files.
cl /EHsc /I"C:\Program Files\boost\boost_1_53_0" Client.cpp /link "libboost_system-vc90-mt-s-1_53.lib" /LIBPATH:"C:\Program Files\boost\boost_1_53_0\stage\lib\"