Useful commands used in Windows commands shell


As Unix script language is actually quit powerful to do manipulate text, files/directories and so on, on Windows machine, there are many ways to do the same jobs. Here some useful examples which can be used in normal Windows .bat or .cmd and are also quit helpful in many option menus supported in Visual Studio. For example, before actual compilation of a project, someone may want to copy or create resources necessary to build binary to certain location or add a time stamp string to many source code files. For this purpose, we can add custom commands in Pre-build Event options of Visual Studio property setting window. 


So hope these examples show you a guidance on that. Again this information were taken from various link which I cannot remember correctly.



1. Searching files having specific extension in its file name in current folder


for %%f in (*.java *.cmd) do echo  %%f


2. Searching files with .java extension recursively  


dir /b /s /a-d | findstr /i ".java$


3. Find and delete files with certain name recursivly

 i) In batch file,

    for /f "usebackq" %%i in (`dir /s /b ^| find "Makefile"`) do echo %%i

 ii) In command line,

    for /f "usebackq" %i in (`dir /s /b ^| find "Makefile"`) do echo %i


 ** Note: replace "echo" with "del" to delete file instead of echoing file name.


4. Create array containing file names with full path located in specific folder. Note: In Windows there seems a limitation in assigning array from command line with use of pipe. So this is different trial to do that.

setlocal enabledelayedexpansion enableextensions

set LIST=

for %%x in (javaSourceFolder\*.java) do set LIST= %%x

set LIST=%LIST:~1%


5. Compiling all java files located at specific folder

---- Assuming %LIST% having file list with full path  ---

for %%f in (%LIST%) do (

 "$(JDK_ROOT)\bin\javac.exe" -d $(IntDir)$(JavaOutputDir) -classpath $(IntDir)$(JavaOutputDir) -classpath $(AndroidSdkApiDir)/android.jar %%f

)


6. QT

When you need to decide which build configuration among 32bit and 64bit, don't forget to keep using only one configuration. For example, if you develop qt application using Visual Studio C/C++ 20xx and want to use command prompt to build it, you need to choose build environment among 32bit, 64bit and 64bit_opengl. Once you pick one among them, DON'T FORGET to call proper bat file for Visual Studio compilation setup.


If you want 32bit QT application, run below command after opening QT command prompt

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\vcvarsall.bat" x86


If you want 64bit QT application, run below command after opening QT command prompt

call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\vcvarsall.bat" x64


7. later...


Posted by kevino
,

하나의 소스로 윈도우즈, 리눅스, 맥과 같은 다른 운영체제에서 돌아가는 그래픽 관련 애플리케이션을 작성할때 가장 좋은 구성을 개인적으로 QT 와 cmake패키지의 조합으로 본다. 이와 같은 구성으로 OpenGL이나 OpenCL까지 포함하는 패키지를 구성할 수 있으니 괜찮은 조합으로 생각되어 실제 작성해본 경험을 살려 실제 구동 가능한 소스를 짜는 방법에 대해 설명한다.


본 예제를 컴파일하기 위해 필요한 패키지를 적으면 다음과 같다.


1. CMake v2.8

2. QT 4.8


또한 이 예제는 Windows7과 MAC에서 작성되었다. 그리고 주의할점은 이글의 목적은 어느정도 QT와 Cmake를 사용해본 경험이 있는 사람들을 대상으로 한 것으로 중간에 도움이 될 부분이 필요한 사람들이 읽으면 좋은 수준으로 작성되었슴을 알린다.


애플리케이션 목표기능은 다음과 같다.

OpenGL을 이용하여 화면에 삼각형 출력. 대략 아래와 같은 화면을 출력하는 앱을 작성한다.




작업진행 순서

1. 소스 준비: 소스파일과 헤더 파일 그리고 ui파일을 준비한다.

2-1. qt project생성해서 컴파일 하는 방법

2-2. cmake를 이용한 컴파일 방법



우선 폴더를 하나 만들고 아래의 3개 소스를 작성한다.


main.cpp

GLWidget.h

GLWidget.cpp



다 작성했으면 main.cpp, GLWidget.cpp GLWidget.h 이렇게 세개의 파일이 생겼을 것이다.


그러면 두가지 컴파일 방법이 있는데 우선 쉬운 QT Project를 만드는 방법에 대해 설명한다.


1. QT project 작성


qt를 설치할때 같이 설치되는 qmake를 이용해서 프로젝트 파일을 만드는데 이때 옵션으로 필요한 부분을 추가할수 있는데 여기에서는 OpenGL를 이용하므로 이를 포함시킬수 있는 옵션을 같이 준다.

> qmake -project QT+="core gui opengl"


이렇게 하고 나면  .pro파일이 하나 생길 것인데 이를 QTCreator에서 불러서 컴파일 하면 된다.

이때 부가적으로 Makefile를 생성할 수도 있는데 다음의 명령어를 주면된다.


For MAC: > qmake -spec macx-g++ app.pro

For Window: > qmake app.pro


2. CMake를 이용한 빌드 방법

CMakeLists파일을 작성해야 하는데 문법을 미리 숙지할 필요가 있다. 필자의 여유부족으로 여기에서는 완성된 소스만 보여주고 넘어가기로 한다. 다음 파일을 작성한다.


CMakeLists.txt

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)


SET(TARGET qtglTest)

PROJECT(${TARGET})

SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)


SET(${TARGET}_HEADERS GLWidget.h)

SET(${TARGET}_SOURCES main.cpp GLWidget.cpp)


# Qt4

set(QT_USE_QTOPENGL TRUE)

#FIND_PACKAGE(Qt4 4.6.0 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)

FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)


FIND_PACKAGE(OpenGL)

FIND_PACKAGE(GLUT)

FIND_PACKAGE(GLEW)



QT4_WRAP_CPP(${TARGET}_HEADERS_MOC ${${TARGET}_HEADERS})



INCLUDE(${QT_USE_FILE})

ADD_DEFINITIONS(${QT_DEFINITIONS})


#ADD_DEFINITIONS(-DOBJ_SOURCE_DIR="${${TARGET}_SOURCES}")

MESSAGE ("-- ${TARGET}_SOURCES: ${${TARGET}_SOURCES}")

MESSAGE ("-----------------------------------------")

MESSAGE ("-- QT_INCLUDE_DIR: ${QT_INCLUDE_DIR}")

MESSAGE ("-- QT_LIBRARIES: ${QT_LIBRARIES}")


INCLUDE_DIRECTORIES(

    ${QT_INCLUDE_DIR}

    ${GLUT_INCLUDE_DIR}

    ${OPENGL_INCLUDE_DIR}

    ${GLEW_INCLUDE_PATH}

)



ADD_EXECUTABLE( ${TARGET} ${${TARGET}_SOURCES} ${${TARGET}_HEADERS_MOC})

TARGET_LINK_LIBRARIES ( ${TARGET}

    ${QT_LIBRARIES}

    ${GLUT_LIBRARIES}

    ${OPENGL_LIBRARIES}

    ${GLEW_LIBRARY}

)

#TARGET_LINK_LIBRARIES(clTut ${OPENCL_LIBRARY})



작성이 되었으면 다음의 순서를 진행하여 컴파일 한다.

> mkdir build
> cd build
> cmake ..
> make


이 결과로 생긴 앱을 실행하면 위의 화면을 볼 수 있다.


여기서 필요한 몇가지 cmake 스크립트 파일에 대한 설명을 하지 않았는데 다음의 파일을 받아서 소스폴더에 cmake이름의 폴더를 만들고 집어넣고 위의 명령어를 실행해야 오류가 생기지 않음을 언급해둔다.


전체 소스 파일 받기


qtglTest.zip




Posted by kevino
,