코딩을 완료하고 컴파일을 하려는데 “undefined reference to” 오류가 발생하는 경우가 있습니다.

 

/home/test/ServerComm.cpp:133: undefined reference to `ServerComm::BatchStatistics(char*, char*)'
/home/test/ServerComm.cpp:137: undefined reference to `ServerComm::~BatchStatistics()'
...
collect2: error: ld returned 1 exit status
make: *** [ServerComm.exe] 오류 1

 

이런경우 두가지만 찾아보면 쉽게 오류 해결이 가능 합니다.

 

1. Header 파일에 추가 확인

 

프로그램에 집중해서 작업을 하다 보면 function이 필요해서 추가를 하는데 막상 헤더파일에는 빼놓고 컴파일 하는 경우가 있습니다. 그런 경우에는 여기에서는 BatchStatistics.h 헤더 파일을 열고 빠진 내용을 추가하면 됩니다.

 

class BatchStatistics {
public:
    BatchStatistics(string userId, string month);
    ~BatchStatistics();

 

 

2. Makefile 추가 확인

 

만일 신규로 class 파일을 생성한 거라면 Makefile에 등록을 하지 않아 컴파일시 참조를 할 수 없어서 발생하는 오류 입니다.

 

.SUFFIXES: .o .cpp
%.o : %.cpp
           $(CC) $(CFLAGS) -c $< $(INC)
 
all: ServerComm.exe
SRV_OBJ=Main.o \
           CommServer.o \
           PostgreClass.o \
           BatchStatistics.o \
           User.o          

  

이렇게 Makefile에 추가하고 다시 make rebuild 해주면 undefined reference to 오류는 해결이 됩니다.

 

- copy coding -

 

linux에서 postgresql을 사용하기 위해 psql 명령어를 사용하는데 접속이 되지 않고 아래처럼 오류가 발생하였습니다.

 

[postgres@500115801534 postgresql]$ psql
psql: could not connect to server: 그런 파일이나 디렉터리가 없습니다
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

 

 

이런 오류는 postgres를 실행하지 않아서 발생한다고 되어 있는데 명령어로 확인해 보면

 

$ ps -ef | grep postgres

 

 

프로세스가 잘 실행되고 있습니다.

 

다음으로는 .s.PGSQL.5432 파일이 없어서 그렇다고 하는데 오류에 나와있는 폴더를 찾아가서 확인해 봅니다.

 

$ cd /var/run/postgresql/

$ ls -al

srwxrwxrwx.  1 postgres postgres   0  5 25 16:32 .s.PGSQL.5532

 

파일도 있습니다그렇지만 파일명이 좀 다른것을 확인할 수 있습니다.

 

저의 경우는 postgresqlport 번호를 변경해서 서비스를 하려고 하는 경우 이므로 위에서 시도한 방법으로는 해결이 될 수 없고 옵션을 사용해야 하는 경우 입니다.

 

$ psql -U postgres -p 5532

 

이렇게 psql을 실행할 때 옵션을 추가하면 데이터베이스에 접속이 가능 합니다.

 

여기서 비밀 번호를 요청하는데 postgres의 비밀번호를 입력하면 됩니다.

 

- copy coding -

 

App을 새로 생성해서 테스트 하려고 하니 오류가 나옵니다.

 

Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.

 

 

Gradle을 살펴보고

 

android {
   
compileSdkVersion
31
   
buildToolsVersion "31.0.0"

   
defaultConfig {
       
applicationId
"copycoding.tistory.sample"
       
minSdkVersion 16
       
targetSdkVersion 31
       
versionCode 1
       
versionName "1.0"

       
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   
}

 

설치된 SDK Tool도 살펴봐도

 

 

 

별 문제 없는것 같은데..

 

 

1. 버전 낮추기

 

다시 설치하긴 귀찮고 전체적으로 버전을 30으로 낮추어 봅니다. 

 

android {
   
compileSdkVersion
30
   
buildToolsVersion "30.0.3"

   
defaultConfig {
       
applicationId
"copycoding.tistory.sample"
       
minSdkVersion 16
       
targetSdkVersion 30
       
versionCode 1
       
versionName "1.0"

       
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.5.0'

 

 

이런.  새로운 오류가 발생 합니다.

 

 

ERROR:C:\Users\will\.gradle\caches\transforms-2\files-2.1\4eb2fc21ccc2dce4da190845bc3482ac\material-1.5.0\res\values-v31\values-v31.xml:3:5-94: AAPT: error: resource android:color/system_neutral1_1000 not found.

 

Material Component Library 버전이 업데이트 되어서 31을 사용해야 한다고 합니다.

답을 찾았네요.  material 버전을 낮추면 되는거군요.

 

android {
   
compileSdkVersion 30
   
buildToolsVersion "30.0.3"

    
defaultConfig {
       
applicationId
"copycoding.tistory.sample"
       
minSdkVersion 16
       
targetSdkVersion 30
       
versionCode 1
       
versionName "1.0"

       
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
   
}

   
buildTypes {
       
release {
           
minifyEnabled
false
           
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
       
}
    }
   
compileOptions {
       
sourceCompatibility JavaVersion.
VERSION_1_8
       
targetCompatibility JavaVersion.VERSION_1_8
   
}
}



dependencies {

   
implementation 'androidx.appcompat:appcompat:1.3.1'
   
implementation 'com.google.android.material:material:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
   
testImplementation 'junit:junit:4.+'
   
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
   
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

  

material 버전을 1.5.0에서 1.2.0으로 변경 하나 잘 됩니다.  물론 1.4.0로 낮추어도 됩니다.

 

 

 

 

2. buildToolsVersion 낮추기

 

다른건 그대로 두고 buildToolsVersion만 낮추어서 해결해 봅니다.

Android Studio에서 Gradle을 열고 오른쪽 상단을 보면 Open (Ctrl+Alt+Shift+S)가 있는데

 

 

이걸 누르면 창이 하나 뜨고

 

 

여기서 Build Tools Version을 확장하여 31.0.0 대신 하나 낮은걸 선택 합니다.

  

android {
   
compileSdkVersion
31
   
buildToolsVersion '30.0.3'

   
defaultConfig {
       
applicationId
"copycoding.tistory.test"
       
minSdkVersion 16
       
targetSdkVersion 31
       
versionCode 1
        
versionName "1.0"

 

 

 

그리고 실행하면 다른 오류가 발생 합니다.

 

Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

 

 

android:exported 이게 문제라는 군요.  참조하라는 링크를 따라가보면 설명이 있습니다.

https://developer.android.com/guide/topics/manifest/activity-element#exported

 

어째든 android:exportedManifest에 추가하고 값을 넣으면 됩니다.  만일 false를 넣으면 앱이 생성은 되는데 실행하려고 하면 app is’nt installed라는 토스트만 나오니 true를 적어 줍니다.

값을 설정하는 위치는 activity에 해주어야 합니다.

  

<activity android:name=".MainActivity"
   
android:exported="true"
>
    <
intent-filter>
        <
action android:name="android.intent.action.MAIN" />

        <
category android:name="android.intent.category.LAUNCHER" />
    </
intent-filter>
</
activity>

 

이렇게 하면 앱을 잘 테스트할 수 있습니다.

 

 

이건 제가 간단한 테스트를 하려고 한것이고 실제로는 높은 버전으로 컴파일 해야 최신 핸드폰에서도 잘 돌아가는 앱을 만들 수 있겠죠.

 

- copy coding -


Spring Boot에서 jsp로 화면을 만들고 Controller에서 View로 리턴을 하였는데 jsp 파일을 찾지 못하는 경우 ResourceHttpRequestHandler :Path with "WEB-INF" or "META-INF" 이런 식으로 발생하는 오류입니다브라우저에는 아래와 같은 오류가 발생 하고


spring boot jasper


Console에도 아래 처럼 오류 로그를 확인할 수 있습니다


spring boot jasper


spring boot jasper


2020-02-14 11:54:00.941  INFO 33124 --- [nio-9090-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...

2020-02-14 11:54:01.089  INFO 33124 --- [nio-9090-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.

2020-02-14 11:54:01.151  WARN 33124 --- [nio-9090-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/board/BoardList.jsp]

2020-02-14 11:54:05.743  WARN 33124 --- [nio-9090-exec-2] o.s.w.s.r.ResourceHttpRequestHandler     : Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/welcome.jsp]


사실 오류라기 보다는 Spring Boot에서 내장된 Tomcat을 사용 하는 경우 JSP를 처리하는 서블릿을 추가하지 않아 발생하는 것으로 pom.xml에 다음을 추가해 주면 해결 됩니다.


 <dependency>

        <groupId>org.apache.tomcat.embed</groupId>

        <artifactId>tomcat-embed-jasper</artifactId>

</dependency>


pom.xml에 추가하고  Maven update 하고 Maveninstall 하고 실행해 보면 이번에는 화면에 출력이 잘 나옵니다.



123

+ Recent posts