ホーム » Linux

Linux」カテゴリーアーカイブ

2024年4月
 123456
78910111213
14151617181920
21222324252627
282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,212 アクセス



フォルダの更新日時の設定

以前に作成した mtime を更新するツール
データファイルなどの更新日時を揃えるために作成したもの.
更新日時の設定は CFile::SetStatus で行っている.

	CString		file = UpdateFiles[index] ;
	CFileStatus	fs ;
	CFile::GetStatus(file,fs) ;
	fs.m_mtime = newTime ;
	CFile::SetStatus(file,fs) ;

このツールではフォルダの更新日時は変更できない.


その後 Linux 環境などでも動作する様なコードを作成
utime を使用したもの.
Linux 環境ではフォルダに対してもうまく動作するが,Windows 環境では相変わらず.
DS220  utime
ここまでは,以前調べたもの


2ヶ月ほど前だったと思うが,検索していて次のページを見つけた.
ファイル・フォルダーの更新日時を変更


改めて CFile::SetStatus や _utime の中身を見ると,動作は同じで ::CreateFile と ::SetFileTime を呼出している.
デバッガで追いかけていると ::CreateFile で失敗している.errno は 13 .
::CreateFile を次の様に指定して呼出すと,ファイルの場合は問題ないがフォルダは NG .

HANDLE  hFile = ::CreateFile(file_name,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,     NULL) ;

フォルダの場合 FILE_FLAG_BACKUP_SEMANTICS が指定されていなければならないみたい.

HANDLE  hFile = ::CreateFile(file_name,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL) ;

time_t から FILETIME への変換は次の所.
https://learn.microsoft.com/ja-jp/windows/win32/sysinfo/converting-a-time-t-value-to-a-file-time
SetFTime.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux での GLUT 3D データ表示

昨日のコードをもう少し汎用的に修正.そしてそれを他から呼出せるように変更.
次の様なコードで 3D データを生成して,GLUT で表示できる様にした.

bool	test	(void)
{
	Vd2A	pts ;
	{
		pts.push_back(Vd2(  0,  0)) ;
		pts.push_back(Vd2( 70,  0)) ;
		pts.push_back(Vd2( 90, 50)) ;
		pts.push_back(Vd2(100,100)) ;
		pts.push_back(Vd2( 50,100)) ;
		pts.push_back(Vd2( 30, 70)) ;
		pts.push_back(Vd2( 40, 30)) ;
		pts.push_back(Vd2(  0,  0)) ;
		}
	vv_PLF	vvplf ;
	{
		Vd3A	v3a = ::ToVd3A(pts) ;
		Vd4A	v4a = ::ToVd4A(v3a) ;
		PLF	plf_l__ (PLF::line,v4a) ;
		PLF	plf_f__ (PLF::face,v4a) ;
		v_PLF	v_plf ;
			v_plf.push_back(plf_l__) ;
			v_plf.push_back(plf_f__) ;
			vvplf.push_back(v_plf) ;
		}
	tstring	txt_name = ::g3_d_get_txt_name() ;
	{
		tstring	tmp_path = ::Get_i_Tools_tmp_date() ;
		tstring	ipl_name = ::Path_AddLastSP(tmp_path) + ::Now_Format(_T("%H%M%S")) + _T(".ipl") ;
		::To_ipl  (vvplf,ipl_name.c_str()) ;
		::SaveText(txt_name.c_str(),ipl_name) ;
		}
	{
		::exec_g3_d(txt_name.c_str()) ;
		}
	return	true ;
	}

g3_d_gl

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

GLUT を使用した 3D データの表示

個人的なメモです.
4 年位前に作成したコードで,凹多角形がうまく処理できていないものがあったのでその変更.

#include	"glut_cg.hxx"
#include	"gonsa_to.hxx"

#define		TIMING_DN	1000

//	int	_tmain	(int argc, _TCHAR* argv[])
int		main	(int argc,   char* argv[])
{
	{
		GonsA	gnsa ;
		{
			tstring	buf ;	buf.resize(1000) ;
			while (std::terr << _T("file ? =") , std::tin.getline(&buf[0],buf.size()))
			{
				tstring	str = buf.c_str() ;
				if 	(str == _T("q"))    {	break ;		}
				else if (str == _T("Q"))    {	break ;		}
				str = ::QuotM_Del_All(str) ;
				if (str.empty())            {	continue ;	}
				if (::File_IsNothing(str))  {	continue ;	}
				tstring	in_file = str ;
				gnsa = ::To_GonsA(in_file.c_str()) ;
				gnsa = ::GonsA_Triangulation(gnsa) ;		//	2023/06/27
				gnsa = ::GonsA_CalcNormal   (gnsa) ;		//	2023/06/27
				if (gnsa.size() > 0)        {	break ;		}
				}
			if (gnsa.size() == 0)           {	return	0 ;		}
			}
		::set_GonsA(gnsa) ;
		::set_Extent(::GonsA_GetExtent(gnsa)) ;
		}
	::glutInitWindowPosition(200,200) ;
	::glutInitWindowSize    (600,400) ;
	::glutInitDisplayMode   (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) ;
	::glutInit              (&argc,argv) ;
	::glutCreateWindow      (argv[0]) ;
	::glutReshapeFunc       (cv_resize) ;
	::glutDisplayFunc       (cg_display) ;
	::glutKeyboardFunc      (cv_keyboard) ;
	::glutMouseFunc         (cv_mouse) ;
	::glutMotionFunc        (cv_motion) ;
	::glutTimerFunc         (TIMING_DN,cv_timer,TIMING_DN) ;
	::cv_init               () ;
	{
		::glEnable(GL_LIGHTING) ;
		::glEnable(GL_LIGHT0) ;
		}
	::glutMainLoop          () ;
	return	0 ;
	}

#include	"messbar.cxx"

t_gl_b_3.cpp
t_gl_b_3.exe

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Linux VS Code インストール

Fedora 環境に VS Code のインストール.
Fedora Linux に Visual Studio Code をインストールする方法
最初の次のコマンドで,時間がかかっている.
sudo dnf upgrade –refresh
それで調べているともっと簡単と思われる情報が…
Visual Studio Code – Fedora Project Wiki
次のコマンドでインストール.
flatpak install https://flathub.org/repo/appstream/com.visualstudio.code.flatpakref
何とか入った.
Fedora に VS Code のインストール
が,どうやって使うのか…


Ubuntu 環境は OS が古く,20.04 への更新から.
さらに flatpak をインストールする必要があった.
sudo apt install flatpak
そして,
flatpak install https://flathub.org/repo/appstream/com.visualstudio.code.flatpakref
Ubuntu 環境に VS Code のインストール
こちらの方は「日本語化」のインストールの案内が自動で出てきた.
Fedora 環境では,手動で追加.
VS Code  日本語化パッケージのインストール
「言語拡張機能の参照」をクリック.すると,左に「C#」などがリストされる.
VC Code に C# のインストール


.NET のインストール.
Linux に .NET をインストールする
dotnet と入力すると,sudo snap install dotnet-sdk と出てきた.
Ubuntu に dotnet-sdk をインストール
これは違った?


次の所にある C# のコードを作成して VS Code で「デバッグなして実行」.
コンソール アプリ
すると,また同じ所に.
Ubuntu に .NET SDK または .NET ランタイムをインストールする
順に入れたが…

wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

sudo apt-get update &&   sudo apt-get install -y dotnet-sdk-6.0

よくわからない.


次の所を参考にコマンドで…
Linux での開発用に C# を設定する
次のコマンドを入力すると…
dotnet new console
そして,
dotnet run
dotnet new console と dotnet run
何とか,コンパイル,実行できることは確認できた.


今度は Fedora 環境に.
Fedora に .NET SDK または .NET ランタイムをインストールする
sudo dnf install dotnet-sdk-6.0
dotnet new console と dotnet run
Fedora で dotnet new console と dotnet run


2022/11/25
Windows 環境だと…
dotnet new winforms
dotnet new <テンプレート>


VS Code はエディタとして使用する程度?
チュートリアル: Visual Studio Code を使用して .NET コンソール アプリケーションを作成する
うまく動作しない.ターミナルからでは dotnet コマンドへのパスが通っていない?

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

簡易 Web サーバ

次の様なものをブラウザで表示するために…
http://mish.html.xdomain.jp/Test/WebGL/Sphere.html


「Web Server for Chrome」は以前書いた.
http://test_wp.mish.work/2022/01/chrome-web.html
Win11 環境で同様に実行すると,次の様な表示が…
「Web Server for Chrome」は現在サポートされていません


開発環境には VS 2022 などが入っているので Python を使用した方法
…\Test\Web\WebGL\ に html などをコピー.
コマンドプロンプトで …\Test に移動.
py -m http.server
これで 127.0.0.1:8000 でアクセスできる.
終了は「Ctrl」+「C」.
py -m http.server


ASUSTOR NAS だと,
python -m http.server
python -m http.server
QNAP NAS や Synology NAS でも同様.Raspberry Pi にもあった.


検索すると System.Net.HttpListener.dll と言うのが見つかる.
それを使っていると思われる次の所からコードを拝借.
Windows 標準で Web サーバを起動する
System.Net.HttpListener.dll
勉強を兼ねて,ちょっとやってみるか.


2023/01/17
https://jml.mish.work/index.php/i-tools/web-svr.html
C++/CLI で作成した 簡易 Web サーバ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Fedora 34 で GLUT が動作しない?

仮想マシンの Fedora 32 を 34 に更新.
動作を確認していると,GLUT を使用した .out がうまく動作しない.
起動はしているが,ウィンドウが表示されない?
コンパイルなどはできている.
実行するとコンソールにはウィンドウを表示する前の部分は表示される.
いろいろやったがダメで,再起動.
Fedora 34 GLUT
うまく表示する様になった.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

::GetDiskFreeSpaceEx , ::statvfs

Win9x が多く存在していた頃のコードの MFC を使用しない方法での書き直し.
前のものは次の様になっている.

//	J048221	SDK32:GetDiskFreeSpace と GetDiskFreeSpaceEx について
typedef BOOL (WINAPI *P_GDFSE)(LPCTSTR, PULARGE_INTEGER,PULARGE_INTEGER, PULARGE_INTEGER);
// ..
	fResult = ::GetDiskFreeSpace(pszDrive,&SectorsPerCluster,&BytesPerSector,&FreeClusters,&TotalClusters) ;
	if (fResult) {
		TotalBytes    	= (__int64)TotalClusters * SectorsPerCluster * BytesPerSector ;
		TotalFreeBytes	= (__int64)FreeClusters  * SectorsPerCluster * BytesPerSector ;
		FreeBytesAvailable = TotalFreeBytes ;
		}
// ..
{
	P_GDFSE	pGetDiskFreeSpaceEx = NULL;
	#ifdef UNICODE
		pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"GetDiskFreeSpaceExW") ;
	#else
		pGetDiskFreeSpaceEx = (P_GDFSE)GetProcAddress(GetModuleHandle(_T("kernel32.dll")),"GetDiskFreeSpaceExA") ;
	#endif
	if (pGetDiskFreeSpaceEx) {
		fResult = pGetDiskFreeSpaceEx (pszDrive,
			(PULARGE_INTEGER)&FreeBytesAvailable,
			(PULARGE_INTEGER)&TotalBytes,
			(PULARGE_INTEGER)&TotalFreeBytes);
		}
	}

J048221 SDK32:GetDiskFreeSpace と GetDiskFreeSpaceEx について
https://www.betaarchive.com/wiki/index.php?title=Microsoft_KB_Archive/231497


Windows 環境では次の様な感じ?

class	DiskFree	{
public:
	DiskFree ()	{	Free = Total = 0 ;	}
public:
	u_64	Free ;
	u_64	Total ;
	} ;

DiskFree	GetDiskFree	(LPCTSTR path)
{
	DiskFree	df ;
	u_64		freeC = 0 ;
	u_64		free  = 0 ;
	u_64		total = 0 ;
	if (::GetDiskFreeSpaceEx(path,(PULARGE_INTEGER)&freeC,(PULARGE_INTEGER)&total,(PULARGE_INTEGER)&free)) {
		df.Free = free ;
		df.Total= total;
		}
	return	df ;
	}

Linux 環境では ::statvfs が使えるみたいで,次の様なコードで取得してデバッガで確認.

#include    <iostream>
#include    <sys/statvfs.h>

int main()
{
	struct statvfs	vfs = { 0 } ;
	::statvfs(".", &vfs) ;
	return 0 ;
	}
vfs     	{...}           	statvfs
  f_bsize 	4096            	unsigned long
  f_frsize	4096            	unsigned long
  f_blocks	1452408524      	__fsblkcnt_t
  f_bfree 	200259802       	__fsblkcnt_t
  f_bavail	199469255       	__fsblkcnt_t
  f_files 	183001088       	__fsfilcnt_t
  f_ffree 	181248356       	__fsfilcnt_t
  f_favail	181248356       	__fsfilcnt_t
  f_fsid  	3941329918106335254	unsigned long
  f_flag  	4096            	unsigned long
  f_namemax	255             	unsigned long
  __f_spare	                 	int [6]
    [0]   	0               	int
    [1]   	0               	int
    [2]   	0               	int
    [3]   	0               	int
    [4]   	0               	int
    [5]   	0               	int

Debian10 ::statvfs

Iwao@AS5202T:/volume1/home/Iwao $ cd gcc_test/Test/t_linux/T_vfs/T_s_vfs/
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/T_vfs/T_s_vfs $ ll
total 12
drwxrwxrwx    2 Iwao     users       4.0K Jul  1 22:01 ./
drwxrwxrwx    4 Iwao     users       4.0K Jul  1 22:00 ../
-rwxrwxrwx    1 Iwao     users        581 Jul  1 21:55 T_s_vfs.cpp*
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/T_vfs/T_s_vfs $ cat T_s_vfs.cpp
#include    <iostream>
#include    <clocale>

#include    <sys/statvfs.h>

#include    "_tdefine.hxx"
#include    "t_tstrng.hxx"

int     _tmain  (int argc,TCHAR* argv[])
{
        _tsetlocale(LC_ALL,_T("")) ;
        {
                struct  statvfs vfs = { 0 } ;
                if (::statvfs(".", &vfs) == 0) {
                        u_64    free = vfs.f_bavail * vfs.f_frsize ;
                        u_64    total= vfs.f_blocks * vfs.f_frsize ;
                        std::tout << ::To_tstring_Ki(free) << _T(" / ") << ::To_tstring_Ki(total) << std::endl ;
                        std::tout << ::To_tstring_cs(free) << _T(" / ") << ::To_tstring_cs(total) << std::endl ;
                        }
                }
        return  0 ;
        }
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/T_vfs/T_s_vfs $ g++ T_s_vfs.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/T_vfs/T_s_vfs $ ./a.out
760.90 G /   5.41 T
817,005,420,544 / 5,949,065,314,304
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/T_vfs/T_s_vfs $

AS5202T  ::statvfs
diskfree.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

NAS lxcdebian10 と VC 2019

ASUSTOR NAS 上の Debian と VC 2019 を使用してのビルドとデバッグ.
VC で次の様なエラーになっている.

lxcdebian10 にツールがありません: gdb rsync zip

lxcdebian10 にツールがありません: gdb rsync zip
次の所にある様に必要なものをインストール.
Linux development with C++ in Visual Studio
gdb rsync zip のインストール
丁度 1 年前にやっていた みたいで,その時より 安定したか?

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

C2664

スタックを使用した次の様なコード.

	stack_s	so ;

エラー情報を指定する様に変更してビルド.

	i_error	ie ;
	stack_s	so(&ie) ;
--------------------Configuration: t_stack - Win32 Debug--------------------
Compiling...
t_stack.cpp
d:\document\vs\vs\1998\t_stack\t_stack\t_stack.cpp(14) : error C2664: '__thiscall stack_s::stack_s(const class stack_s &)' : cannot convert parameter 1 from 'class i_error *' to 'const class stack_s &'
        Reason: cannot convert from 'class i_error *' to 'const class stack_s'
        No constructor could take the source type, or constructor overload resolution was ambiguous
Error executing cl.exe.

T_stack.exe - 1 error(s), 0 warning(s)

C2664 になってしまう.

class	stack_b	{
public:
		stack_b		(i_error* i_err=NULL)	{	ie = &tmp_ie ;	if(i_err != NULL) {	ie = i_err ;	}	}
protected:
	i_error		tmp_ie ;
	i_error*	ie ;
	} ;

class	stack_s	:	public	stack_b	{
public:
//		stack_s		(i_error* i_err=NULL)	:	stack_b	(i_err)		{	;	}
public:
	virtual	bool	push	(c_tstring& s) ;
	virtual	tstring	pop 	(void) ;
	virtual	tstring	last	(void) ;
protected:
	s_tstring	stck_s ;
	} ;

コメントにしている stack_s のコンストラクタを追加すれば OK .
C2664  stack
独習 C++ 7.3 223 ページ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

OPENFILENAME

コンソール AP では,標準入力を使用していた.

#include	"quotm.hxx"
#include	"existff.hxx"

inline	bool	Test	(void)
{
	while(true)	{
		tstring	str ;
		{
			tstring	buf ;
			buf.resize(1000) ;
			std::terr << _T("file ...=") ;
			std::tin.getline(&buf[0],std::streamsize(buf.size())) ;
			str = buf.c_str() ;
			if   	(str == _T("q"))	{	break ;		}
			else if (str == _T("Q"))	{	break ;		}
			str = ::QuotM_Del_All(str) ;
			if (str.empty())   		{	continue ;	}
			}
		{
			if (::File_IsNothing(str)) 	{	continue ;	}
			std::tout << str << std::endl ;
			}
		}
	return	true ;
	}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	{
		Test() ;
		}
	return	0 ;
	}

以前作成した CFileDialog を使用したもの.

#include	<afxwin.h>
#include	"F_Dialog.hxx"
#include	"quotm.hxx"

inline	bool	Test	(void)
{
	while(true)	{
		tstring	str ;
		{
			str = ::FD_GetOpenFile(_T("./")) ;
			if (str.empty())   		{	break ;		}
			}
		{
			if (::File_IsNothing(str))	{	continue ;	}
			std::tout << str << std::endl ;
			}
		}
	return	true ;
	}

CWinApp theApp;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
		std::terr << _T("error : AfxWinInit") << std::endl ;
		nRetCode = 1;
		}
	else  {
		Test() ;
		}
	return nRetCode;
	}

////////////////////////////////////////////////////////////////////////////////////////

#include	<AfxExt.h>
#include	"BrowseFF.cxx"

「開く」ダイアログを表示するだけのコード.

{
	OPENFILENAME	ofn =	{	0	} ;
	ofn.lStructSize = sizeof(OPENFILENAME) ;
	if (!::GetOpenFileName(&ofn))	{	return	tstring() ;	}
//	...
	}

OPENFILENAME の指定が複雑なので,使いそうな内容でまとめてみた.

OPENFILENAME
lStructSize sizeof(OPENFILENAME)
hwndOwner NULL の時,モードレスになる.
CFileDialog では DoModal で求めている.
lpstrFile 選択されたファイル名が入る.
OFN_ALLOWMULTISELECT の場合は,下のメモリイメージ.
nMaxFile lpstrFile で確保している領域の文字数

OFN_ALLOWMULTISELECT の場合の結果の lpstrFile .

0x02C00078  44 3a 5c 44 6f 63 75 6d 65 6e 74 5c 56 53 5c 56  D:\Document\VS\V
0x02C00088  53 5c 32 30 30 35 5c 54 5f 4f 70 65 6e 46 5c 54  S\2005\T_OpenF\T
0x02C00098  5f 4f 46 5f 4d 46 43    54 5f 4f 46 5f 4d 46 43  _OF_MFC.T_OF_MFC
0x02C000A8  2e 42 41 4b    54 5f 4f 46 5f 4d 46 43 2e 63 70  .BAK.T_OF_MFC.cp
0x02C000B8  70    54 5f 4f 46 5f 4d 46 43 2e 76 63 70 72 6f  p.T_OF_MFC.vcpro
0x02C000C8  6a    54 5f 4f 46 5f 4d 46 43 2e 76 63 70 72 6f  j.T_OF_MFC.vcpro
0x02C000D8  6a 2e 5a 31 37 30 53 30 2e 49 77 61 6f 2e 75 73  j.Z170S0.Iwao.us
0x02C000E8  65 72       00 00 00 00 00 00 00 00 00 00 00 00  er..............

0x027E6B50  44 00 3a 00 5c 00 44 00 6f 00 63 00 75 00 6d 00 65 00 6e 00 74 00 5c 00 56 00 53 00 5c 00 56 00  D:\Document\VS\V
0x027E6B70  53 00 5c 00 32 00 30 00 30 00 35 00 5c 00 54 00 5f 00 4f 00 70 00 65 00 6e 00 46 00 5c 00 54 00  S\2005\T_OpenF\T
0x027E6B90  5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00  _OF_MFC.T_OF_MFC
0x027E6BB0  2e 00 42 00 41 00 4b 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 2e 00 63 00 70 00  .BAK.T_OF_MFC.cp
0x027E6BD0  70 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 2e 00 76 00 63 00 70 00 72 00 6f 00  p.T_OF_MFC.vcpro
0x027E6BF0  6a 00 00 00 54 00 5f 00 4f 00 46 00 5f 00 4d 00 46 00 43 00 2e 00 76 00 63 00 70 00 72 00 6f 00  j.T_OF_MFC.vcpro
0x027E6C10  6a 00 2e 00 5a 00 31 00 37 00 30 00 53 00 30 00 2e 00 49 00 77 00 61 00 6f 00 2e 00 75 00 73 00  j.Z170S0.Iwao.us
0x027E6C30  65 00 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  er..............

lpstrFile	0x02c10078 "D:\Document\VS\VS\2005\T_OpenF\T_OF_MFC\ReadMe.txt"	char *

デバッガで OPENFILENAME_SIZE_VERSION_400 となる様にしたもの.
OPENFILENAME_SIZE_VERSION_400


MFC 9 で bVistaStyle を FALSE とすると
CFileDialog bVistaStyle == FALSE
VC 8 exe と同様の,左側がフォルダツリーではない表示のもの.
デフォルトの TRUE だと
CFileDialog bVistaStyle == TRUE
COM を利用したもの?
Common Item Dialog


今度は MFC を使用しない方法.
::GetOpenFileName を使用する方法で OFN_ALLOWMULTISELECT を指定すると実行されなかった.
見た目のエラーにはならない?が,API を呼んで FALSE で抜けてくる.
::CommDlgExtendedError で調べると FNERR_INVALIDFILENAME だった.
存在しないファイル名などを与えるとうまくないみたい.
まだ何か足りないみたいで Win3.x 頃の表示になってしまった.
GetOpenFileName  Win3.x
選択したファイル名などもスペースで区切られている.
OFN_ALLOWMULTISELECT を指定する時は OFN_EXPLORER も指定する必要があるみたい.
次の所に書かれていた.
OPENFILENAMEW structure (commdlg.h)
OFN_ALLOWMULTISELECT | OFN_EXPLORER の場合 lpstrFile に存在しないファイル名でも問題なさそう.


複数選択可能な「開く」ダイアログのコードは次の様な感じ.

tstring	GetOpenFile	(LPCTSTR default_name=_T("./"))
{
	HWND	hwnd = ::GetConsoleHwnd() ;
	tstring	str_file = default_name ;
	    	str_file.resize(260*100) ;
	OPENFILENAME	ofn =	{	0	} ;
	{
		ofn.lStructSize	= sizeof(OPENFILENAME) ;
		ofn.hwndOwner	= hwnd ;
		ofn.nMaxFile	= DWORD(str_file.size()) ;
		ofn.lpstrFile	= &str_file[0] ;
		ofn.Flags   	= OFN_ALLOWMULTISELECT | OFN_EXPLORER | OFN_HIDEREADONLY ;
		}
	if (!::GetOpenFileName(&ofn)) {
		DWORD	err = ::CommDlgExtendedError() ;
		std::terr << ::To_tstring(u_32(err),16) << std::endl ;
		return	tstring() ;
		}
	tstring	sel_file ;
	{
		sel_file = ofn.lpstrFile ;
	//	...
		}
	return	sel_file ;
	}

拡張子のフィルタなどは指定していない.また,選択されたファイルを取得するコードもこれから.


選択されたファイルを取得するコード.

tstring	String_Change	(c_tstring& str_,const TCHAR src,const TCHAR dst)
{
	tstring	str = str_ ;
	for (size_t index=0 ; index<str.size() ; index++) {
		TCHAR	ch = str[index] ;
		if (ch == src) {
			str[index] = dst ;
			}
		}
	return	str ;
	}

	tstring	sel_file ;
	{
		sel_file = ofn.lpstrFile ;
		sel_file = str_file ;
		sel_file = ::String_Change(ofn.lpstrFile,_T('\x0'),_T('\n')) ;
		sel_file = ::String_Change(str_file,     _T('\x0'),_T('\n')) ;
		sel_file = ::String_TrimBoth(sel_file) ;
		}

ofn.lpstrFile は ASCIIZ となってしまうので,str_file をそのまま使用する必要がある.
Win3.x 形式の lpstrFile のダンプ.

0x02311F00  0043 003a 005c 0055 0053 0045 0052 0053 005c 0050 0055 0042 004c 0049 0043 005c  C.:.\.U.S.E.R.S.\.P.U.B.L.I.C.\.
0x02311F20  0044 004f 0043 0055 004d 0045 004e 0054 0053 005c 0020 0042 0061 0063 006b 0043  D.O.C.U.M.E.N.T.S.\. .B.a.c.k.C.
0x02311F40  0050 002e 0062 0061 0074 002e 006c 006e 006b 0020 0057 0049 004e 0031 0030 002d  P...b.a.t...l.n.k. .W.I.N.1.0.-.
0x02311F60  007e 0031 002e 004c 004e 004b 0020 005a 0031 0037 0030 0044 004f 007e 0031 002e  ~.1...L.N.K. .Z.1.7.0.D.O.~.1...
0x02311F80  004c 004e 004b 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  L.N.K...........................

区切りがスペースになるため,ファイル名などにスペースが含まれている場合は 8.3 形式 になる.


lpstrFilter を指定.

	tstring	filter ;
		filter	+= _T("Executable Files (*.exe)|*.exe|") ;
		filter	+= _T("All Files (*.*)|*.*|") ;
		filter	+= _T("|") ;
		filter   = ::String_Change(filter,_T('|'),_T('\x0')) ;
	OPENFILENAME	ofn =	{	0	} ;
	{
		ofn.lStructSize	= sizeof(OPENFILENAME) ;
	//	...
		ofn.lpstrFilter	= &filter[0] ;
		}

ここまでのものを WinXP 環境で表示すると
GetOpenFileName WinXP


WFDialog.hxx

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Ubuntu Linux Station

先日 Linux Station がうまく動作しなくなったように思ったが…
ファームアップデート後,試しに起動するとうまくいった.
先日は,メモリが足りなかったとかだったのか?


GLUT を使える様に インストール
sudo apt install freeglut3 freeglut3-dev
Ubuntu Lunux Station GLUT
ASUSTOR NAS Linux Center Debian 環境の a.out を実行.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

なんかおかしい? DS116 localtime

2020/12/02 0 時過ぎ,個人的に書いているコードがうまく動作していないことに気づいた.
全てではないが,日時の表示が GMT になってしまっている?
うまく動作しているものもあり,次のものは正しく表示される.
DrawNow アクセス日時を WebGL で表示する
この様になった心当たりはある.
昨日 opkg の update と upgrade ,opkg install gcc などを行ったことが影響している?
tree … -D や cal なども GMT になっている.


どこが影響しているかを調べるために少しコードを書いてみた.

#include	<clocale>
#include	<iostream>
#include	"_tdefine.hxx"
#include	"timefmt.hxx"

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		tstring	now_time = ::Now_Format() ;
		std::tout << _T("::Now_Format()   \t") << now_time << std::endl ;
		}
	{
		tstring	gmt_time = ::Now_FormatGMT() ;
		std::tout << _T("::Now_FormatGMT()\t") << gmt_time << std::endl ;
		}
	return	0 ;
	}

Win10 環境では意図した動作.

Microsoft Windows [Version 10.0.18363.1198]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Iwao>\\TestXP\C_Temp\Test_cpp\t_mtime\t_localt\Release.060\t_localt.exe
::Now_Format()          2020/12/02 10:22:34
::Now_FormatGMT()       2020/12/02 01:22:34

C:\Users\Iwao>  

Win10 で localtime


DS116 では localtime が正しく求まっていない.

Iwao@DS116:~/gcc_test/Test/t_linux/t_mtime/t_localt$ ll
total 44
drwxrwxrwx+ 2 Iwao users  4096 Dec  2 10:19 .
drwxrwxrwx+ 5 Iwao users  4096 Dec  2 10:03 ..
-rwxrwxrwx  1 Iwao users 14188 Dec  2 10:19 a.out
-rwxrwxrwx+ 1 Iwao users   892 Dec  2 10:02 t_localt.BAK
-rwxrwxrwx+ 1 Iwao users   917 Dec  2 10:17 t_localt.cpp
-rwxrwxrwx+ 1 Iwao users  4476 Dec  2 10:02 t_localt.dsp
Iwao@DS116:~/gcc_test/Test/t_linux/t_mtime/t_localt$ ./a.out
::Now_Format()          2020/12/02 01:24:30
::Now_FormatGMT()       2020/12/02 01:24:30
Iwao@DS116:~/gcc_test/Test/t_linux/t_mtime/t_localt$  

DS116 で localtime


上の WebGL で現在日時を表示ている .out は,2017/07/19 にコンパイルしたもの.
他の .out で,古いものは正しく動作し,2020/02 のものはうまくない.


どこかに設定などがあるのか?


2020/12/09
GMT と同じ扱いになり困っていたのは,個人的なコードの i_drawlg.hxx
今日のファイルを求める所で 24*60*60 を加えることで対応.


2022/06/15 DS116 entware
entware の更新で正しく動作する様になった.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

NAS 上で OpenMP ?

今まで Windows 上で動かしていた OpenMP 対応のコードを,NAS 上で…
QNAP NAS 上にソースをコピーしてコンパイルすると

[Iwao@TS253D T_cmb_f]$ g++ T_cmb_f.cpp -Wall -fopenmp
In file included from T_cmb_f.cpp:12:0:
/share/Public/CloudD/GoogleD/Develop/_.SRC/Test/t_g3d_et.hpp:12:10: fatal error: omp.h: No such file or directory
 #include <omp.h>
          ^~~~~~~
compilation terminated.
[Iwao@TS253D T_cmb_f]$ 

もう少し単純なコードで…

#ifdef		_OPENMP
#include	<omp.h>
#endif

#include	<clocale>
#include	<iostream>
#include	"i_define.hxx"

bool	Test	(void)
{
	#ifdef	_OPENMP
		#pragma	omp	parallel for
	#endif
	for (long index=0 ; index<20 ; index++)	{
		#ifdef	_OPENMP
			#pragma	omp	critical	(wait)
		#endif
		std::cout << index << std::endl ;
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		::Test() ;
		}
	return	0 ;
	}
[Iwao@TS253D T_cmb_f]$ cd ../T_omp/
[Iwao@TS253D T_omp]$ g++ T_omp.cpp -Wall -fopenmp
T_omp.cpp:10:10: fatal error: omp.h: No such file or directory
 #include <omp.h>
          ^~~~~~~
compilation terminated.
[Iwao@TS253D T_omp]$

NAS OpenMP コンパイルで "fatal error: omp.h: No such file or directory"


Raspberry Pi で同様に行うと問題ない.
Raspberry Pi 上で OpenMP コンパイル


これとは直接関係ないが,
普通にコンパイルした T_cmb_f を QNAP NAS で実行すると,CPU などの温度が正しく表示されない状態に陥った.



2021/05/24
Ubuntu Linux Station ではうまく動作する.
Linux Station OpenMP
Linux Center でも動作する.
Linux Center OpenMP

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

フォルダの更新日時の変更

今までファイルの更新日時の変更は使っていた.
https://www.vector.co.jp/soft/winnt/util/se500182.html
が,このツールでフォルダの更新日時を変更しようとするとできない.
コードは CFile::SetStatus を使用している.

	CFileStatus	fs ;
	CFile::GetStatus(file,fs) ;
	fs.m_mtime = newTime ;
	CFile::SetStatus(file,fs) ;

CFile::SetStatus の中(…\atlmfc\src\mfc\filest.cpp)を見ると ::SetFileTime を使用している.
また Linux などでも使える utime(…\crt\src\utime.c)も ::SetFileTime を使っている.
VC 6 で作成したものをデバッガで追いかけると ::CreateFile で 0xffffffff が返ってきている.


ASUSTOR NAS で試すと,特に問題なく変更できる.

Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ cat t_utime.cpp
#include        <clocale>

#include        "i_trace.hxx"
#include        "filetime.hxx"
#include        "itls_tmp.hxx"
#include        "c_which.hxx"

int     _tmain  (int argc,TCHAR* argv[])
{
        _tsetlocale(LC_ALL,_T("")) ;
        {
                tstring temp_path = ::Get_i_Tools_tmp_date() ;
                tstring fold_path = ::Path_AddLastSP(temp_path) + ::Now_Format(_T("%H%M%S")) ;
                tstring file_path = ::Path_AddLastSP(temp_path) + ::Now_Format(_T("%H%M%S")) + _T(".tmp") ;
                {
                        ::Folder_Create   (fold_path) ;
                        ::File_CreateEmpty(file_path) ;
                        }
                {
                        time_t  f_time = ::File_GetMTime(file_path.c_str()) ;
                                f_time-= 3600*24*7 ;
                        ::File_SetMTime(file_path.c_str(),f_time) ;
                        ::File_SetMTime(fold_path.c_str(),f_time) ;
                        }
                {
                        tstring cmd     = tstring(cmd_ls_la) + _T(" ") + ::QuotM_Add_Auto(temp_path) ;
                        _tsystem(cmd.c_str()) ;
                        }
                }
        return  0 ;
        }
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ g++ t_utime.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ ll
total 136
drwxrwxrwx    2 Iwao     users       4.0K Nov  7 16:24 ./
drwxrwxrwx    3 Iwao     users       4.0K Nov  7 15:32 ../
-rwxr-xr-x    1 Iwao     users     122.7K Nov  7 16:24 a.out*
-rwxrwxrwx    1 Iwao     users        838 Nov  7 16:22 t_utime.cpp*
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $ ./a.out
total 0
drwxr-xr-x    3 Iwao     users           80 Nov  7 16:24 .
drwxr-xr-x    3 Iwao     users           60 Nov  7 16:24 ..
drwxr-xr-x    2 Iwao     users           40 Oct 31 16:24 162451
-rw-------    1 Iwao     users            0 Oct 31 16:24 162451.tmp
Iwao@AS5202T:/volume1/home/Iwao/gcc_test/Test/t_linux/t_mtime/t_utime $                                  

ASUSTOR NAS AS5202T 上で utime
今日はここまで.


2024/01/04
フォルダの更新日時の設定

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python venv

次の所を参考にして…
VS CodeとFlaskによるWebアプリ開発「最初の一歩」
https://kazuhira-r.hatenablog.com/entry/2019/01/09/231800


cd %TMP% で移動し temp\test\ 以下に作成.
py -m venv temp\test
Win10 環境で py -m venv ...
Linux 環境では,~/Documents/tmp/test/
cd ~/Documents/tmp
python3 -m venv test
Ubuntu 環境で python3 -m venv ...


Win10   .\test\Scripts\activate
Ubuntu  source ./test/bin/activate

Flask の起動は,環境変数 FLASK_APP を設定して flask run らしい.
サンプルにある内容 を python3 sample.py との違いは?


2020/08/24
VS 2017 での仮想環境の作成は「ソリューション エクスプローラー」-「Python 環境」の「右クリック」にある.
VS 2017 Python 仮想環境を追加

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python tkinter インストール

sudo apt install python3-tk
Debian 環境に tkinter インストール
Ubuntu 環境に tkinter インストール


Windows から Raspberry Pi 環境に接続できる様に samba を追加しようと…
検索して次の所を参考に設定.
https://qiita.com/fstyle/items/1670d260f58f77a43144
https://www.raspberrypirulo.net/entry/samba
この中で書かれている nano というエディタ.
CUI で使えるみたいで NAS などの幾つかの環境にインストール.
sudo opkg install nano


他に CUI のファイルマネージャ.
sudo opkg install mc
操作性など異なるが,エコロジーⅡを思い出す.
https://unilab.gbb60166.jp/T98Next/T98Next2.htm

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ – 6

以前調べた時は,Synology NAS と同様に面倒だと思ったが…


検索すると
QNAPにEntware-stdをインストールする
QNAP NAS  QKPG Store の登録
QNAP NAS  Entware-std のインストール

Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Iwao>\\WDCloud\Public\Document\bat\ssh_ts253d.bat

C:\Users\Iwao>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 22 ts253d
Iwao@ts253d's password:
[Iwao@TS253D ~]$ gcc
-sh: gcc: command not found
[Iwao@TS253D ~]$ opkg
-sh: opkg: command not found
[Iwao@TS253D ~]$ /opt/bin/opkg
opkg must have one sub-command argument
usage: opkg [options...] sub-command [arguments...]
where sub-command is one of:

Package Manipulation:
        update                  Update list of available packages
        upgrade <pkgs>          Upgrade packages
        install <pkgs>          Install package(s)
        configure <pkgs>        Configure unpacked package(s)
        remove <pkgs|regexp>    Remove package(s)
        flag <flag> <pkgs>      Flag package(s)
         <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)

...

 regexp could be something like 'pkgname*' '*file*' or similar
 e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'
[Iwao@TS253D ~]$ 
[Iwao@TS253D ~]$ /opt/bin/opkg install gcc
Installing gcc (7.4.0-5) to root...
Downloading http://bin.entware.net/x64-k3.2/gcc_7.4.0-5_x64-3.2.ipk
Installing zlib (1.2.11-3) to root...
Downloading http://bin.entware.net/x64-k3.2/zlib_1.2.11-3_x64-3.2.ipk
Collected errors:
 * wfopen: //opt/lib/opkg/info/zlib.control: Permission denied.
 * extract_archive: Cannot create symlink from ./opt/lib/libz.so to 'libz.so.1': Permission denied.
 * extract_archive: Cannot create symlink from ./opt/lib/libz.so.1 to 'libz.so.1.2.11': Permission denied.
 * wfopen: /opt/lib/libz.so.1.2.11: Permission denied.
 * pkg_write_filelist: Failed to open //opt/lib/opkg/info/zlib.list: Permission denied.
 * opkg_install_pkg: Failed to extract data files for zlib. Package debris may remain!
 * opkg_install_cmd: Cannot install package gcc.
 * opkg_conf_write_status_files: Can't open status file //opt/lib/opkg/status: Permission denied.
 * opkg_conf_write_status_files: Can't open status file /opt/tmp//opt/lib/opkg/status: Permission denied.
[Iwao@TS253D ~]$ 

QNAP NAS ssh 接続 opkg
QNAP NAS opkg install gcc
sudo -i としても入れない.方法がわからなかったので admin で入ることに.

C:\Users\Iwao>ssh -l Iwao ts253d
Iwao@ts253d's password:
[Iwao@TS253D ~]$ sudo -i
Password:
Iwao is not in the sudoers file.  This incident will be reported.
[Iwao@TS253D ~]$
[Iwao@TS253D ~]$
[Iwao@TS253D ~]$ exit
logout
Connection to ts253d closed.

C:\Users\Iwao>ssh -l admin ts253d
admin@ts253d's password:
[~] #
[~] #
[~] #
[/opt/bin] # opkg install gcc  
Installing gcc (7.4.0-5) to root...
Downloading http://bin.entware.net/x64-k3.2/gcc_7.4.0-5_x64-3.2.ipk
Installing zlib (1.2.11-3) to root...
Downloading http://bin.entware.net/x64-k3.2/zlib_1.2.11-3_x64-3.2.ipk
Installing libiconv-full (1.11.1-4) to root...
Downloading http://bin.entware.net/x64-k3.2/libiconv-full_1.11.1-4_x64-3.2.ipk
Installing libintl-full (0.19.8.1-2) to root...
Downloading http://bin.entware.net/x64-k3.2/libintl-full_0.19.8.1-2_x64-3.2.ipk
Installing libbfd (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/libbfd_2.27-1_x64-3.2.ipk
Installing libopcodes (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/libopcodes_2.27-1_x64-3.2.ipk
Installing objdump (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/objdump_2.27-1_x64-3.2.ipk
Installing ar (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/ar_2.27-1_x64-3.2.ipk
Installing binutils (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/binutils_2.27-1_x64-3.2.ipk
Configuring zlib.
Configuring libiconv-full.
Configuring libintl-full.
Configuring libbfd.
Configuring libopcodes.
Configuring objdump.
Configuring ar.
Configuring binutils.
Configuring gcc.
There are no *-dev packages in Entware(with few exceptions)!
Please install headers as described in the wiki:
https://github.com/Entware/Entware/wiki
[/opt/bin] # 

QNAP NAS admin opkg install gcc

https://jml.mish.work/index.php/various/nas/qnap-nas.html

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

NAS 環境に Flask のインストール

先ず Debian 環境に Flask をインストール.
pip3 install Flask
Debian Flask インストール
サンプルの hello.py を実行,ブラウザで表示.
hello.py を実行して,ブラウザで表示


AS5202T でも同様に Flask をインストール.
pip3 install Flask
AS5202T に Flask のインストール
AS5202T で実行,表示


Synology NAS では pip のインストールから.
suto opkg install python-pip
suto opkg install python3-pip
Synology NAS に pip のインストール
Flask をインストールしてみたが …

Iwao@DS116:~/pyt_test/t_flask$ pip3 install Flask
Collecting Flask
  Using cached https://files.pythonhosted.org/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl
Collecting click>=5.1 (from Flask)
  Using cached https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl
Collecting itsdangerous>=0.24 (from Flask)
  Using cached https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Werkzeug>=0.15 (from Flask)
  Using cached https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl
Collecting Jinja2>=2.10.1 (from Flask)
  Using cached https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->Flask)
  Using cached https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'include_package_data'
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'python_requires'
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dsqn65uh/MarkupSafe/
Iwao@DS116:~/pyt_test/t_flask$ 

DS116 に Flask インストール ... エラー?


「 Command python setup.py egg_info faild with error code 1 」で検索 をかけると pip などが古いとある.
次の様にして pip などを更新.
sudo pip install –upgrade pip setuptools
Synology NAS の pip の更新と Flask のインストール

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

Python から CPP の呼出し – 3

////////////////////////////////////////////////////////////////////
//	test_cpp.hpp
//
#pragma		once

#include	"_s_func.hxx"
#include	"_t_func.hxx"
#include	"_tdefine.hxx"

class	test_class	{
public:
			test_class	(LPCTSTR n)	{	name = n ;	std::tout<< name + _T("\t***") << std::endl ;	}
	virtual		~test_class	()      	{	          	std::tout<< name + _T("\t---") << std::endl ;	}
public:
	tstring		name ;
	} ;

inline	test_class*	get_test_class	(void)
{
	static	test_class	G_tc("G_test") ;
	return	&G_tc ;
	}

////////////////////////////////////////////////////////////////////
//	test_cpp.cpp
//
#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	test_class	tc(_T("local 1")) ;
	{
		test_class	tc(_T("local 2")) ;
		std::tout << _T("hello") << std::endl ;
		}
	{
		test_class*	gt = ::get_test_class() ;
		std::tout << gt->name << std::endl ;
		}
	return	0 ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ test_cpp.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ ./a.out
global  ***
local 1 ***
local 2 ***
hello
local 2 ---
G_test  ***
G_test
local 1 ---
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $
////////////////////////////////////////////////////////////////////
//	t_cpp.cpp
//
#include	<Python.h>

#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

static	PyObject*	local__	(PyObject* self, PyObject* args)
{
	test_class	tc(_T("local")) ;
	std::tout << tc.name << std::endl ;
	return	Py_None;
	}

static	PyObject*	global_	(PyObject* self, PyObject* args)
{
	test_class*	gt = ::get_test_class() ;
	std::tout << gt->name << std::endl ;
	return	Py_None;
	}

static	PyMethodDef			t_cpp_methods[] = {
	{	"local__",   	local__,	METH_NOARGS,	"local__"	},
	{	"global_",   	global_,	METH_NOARGS,	"global_"	},
	{	NULL								},
	} ;

static	struct	PyModuleDef	t_cpp = {
	PyModuleDef_HEAD_INIT,
	"t_cpp",
	"test cpp module",
	-1,
	t_cpp_methods
	} ;

PyMODINIT_FUNC	PyInit_t_cpp(void)
{
	return	PyModule_Create(&t_cpp) ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ t_cpp.cpp -Wall -fPIC -shared -o t_cpp.so -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_cpp
global  ***
>>> dir(t_cpp)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'global_', 'local__']
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test  ***
G_test
>>> t_cpp.global_()
G_test
>>> import t_cpp
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test
>>> exit()
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ 

Python から C++ 呼び出し時のコンストラクタ,デストラクタ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し – 2

先日 Python から C を呼び出す関係を調べていて Synology NAS に Python.h がなかった.
検索 をかけると DSM「パッケージ センター」-「Python3」では python-dev が入ってないらしい.


次の様な手順で python-dev をインストール.
# sudo -i
# cd /var/services/homes/Iwao/
# source ./set_ds_inc.sh
# opkg install python-dev
# opkg install python3-dev
Synology NAS に python-dev のインストール
コンパイルで必要なファイルは次の所に入った.
/volume1/@entware-ng/opt/include/python3.6/Python.h
/volume1/@entware-ng/opt/include/python2.7/Python.h
Synology NAS で Python から C の呼出し


Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared
g3d_to.cpp:9:20: fatal error: Python.h: No such file or directory

                    ^
compilation terminated.
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared -I /volume1/@entware-ng/opt/include/python3.6/
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll
total 9568
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 10:29 .
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 09:50 ..
-rwxrwxrwx+ 1 Iwao users 3941375 May  7 18:03 3887.imo
-rwxrwxrwx+ 1 Iwao users 1241865 Jul  7 15:13 7801.imo
drwxrwxrwx+ 2 Iwao users    4096 Aug  5 10:29 bak
-rwxrwxrwx+ 1 Iwao users    1688 Aug  4 15:04 g3d_to.cpp
-rwxrwxrwx  1 Iwao users 2654136 Aug  5 10:29 g3d_to.so
-rwxrwxrwx+ 1 Iwao users    1644 Aug  7  2019 gons_to.cpp
-rwxrwxrwx  1 Iwao users 1931244 Aug  5 10:17 gons_to.out
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ python3
Python 3.6.2 (default, Jan 11 2018, 10:32:53)
[GCC 6.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g3d_to
>>> dir(g3d_to)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'gons_to', 'load', 'save']
>>> g3d_to.load("./7801.imo")
>>> g3d_to.save("./7801.stl")
>>> g3d_to.save("./7801.ac")
>>>
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll
total 10252
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 10:31 .
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 09:50 ..
-rwxrwxrwx+ 1 Iwao users 3941375 May  7 18:03 3887.imo
-rwxrwxrwx+ 1 Iwao users  438369 Aug  5 10:31 7801.ac
-rwxrwxrwx+ 1 Iwao users 1241865 Jul  7 15:13 7801.imo
-rwxrwxrwx+ 1 Iwao users  254784 Aug  5 10:31 7801.stl
drwxrwxrwx+ 2 Iwao users    4096 Aug  5 10:29 bak
-rwxrwxrwx+ 1 Iwao users    1688 Aug  4 15:04 g3d_to.cpp
-rwxrwxrwx  1 Iwao users 2654136 Aug  5 10:29 g3d_to.so
-rwxrwxrwx+ 1 Iwao users    1644 Aug  7  2019 gons_to.cpp
-rwxrwxrwx  1 Iwao users 1931244 Aug  5 10:17 gons_to.out
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ 

DS116 で Python から C++ の呼出し
コンパイル,実行など AS5202T より時間がかかる.


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.